//
#include "MEDFileField.hxx"
+#include "MEDFileMesh.hxx"
#include "MEDLoaderBase.hxx"
#include "MEDFileUtilities.hxx"
#include <algorithm>
-extern med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2];
-extern INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2];
-extern med_geometrie_element typmainoeud[1];
-extern med_geometrie_element typmai3[32];
+extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
+extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
+extern med_geometry_type typmainoeud[1];
+extern med_geometry_type typmai3[32];
using namespace ParaMEDMEM;
MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, med_idt fid) throw(INTERP_KERNEL::Exception)
try:_father(fath)
{
- INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- INTERP_KERNEL::AutoPtr<char> pflname=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ INTERP_KERNEL::AutoPtr<char> locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> pflname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
std::string fieldName=getName();
std::string meshName=getMeshName();
int iteration=getIteration();
const std::vector<std::string>& infos=getInfos();
TypeOfField type=getType();
INTERP_KERNEL::NormalizedCellType geoType=getGeoType();
- int nval=MEDnVal(fid,(char *)fieldName.c_str(),type==ON_CELLS?MED_MAILLE:MED_NOEUD,type==ON_CELLS?typmai3[(int)geoType]:MED_NONE,
- iteration,order,(char *)meshName.c_str(),MED_COMPACT);
+ int profilesize,nbi;
+ int nval=MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,type==ON_CELLS?MED_CELL:MED_NODE,type==ON_CELLS?typmai3[(int)geoType]:MED_NONE,1,MED_COMPACT_PFLMODE,
+ pflname,&profilesize,locname,&nbi);//to generalize
_arr=DataArrayDouble::New();
_arr->alloc(nval,infos.size());
- MEDchampLire(fid,(char *)getMeshName().c_str(),(char *)fieldName.c_str(),(unsigned char*)_arr->getPointer(),MED_FULL_INTERLACE,MED_ALL,locname,
- pflname,MED_COMPACT,type==ON_CELLS?MED_MAILLE:MED_NOEUD,
- type==ON_CELLS?typmai3[(int)geoType]:MED_NONE,
- iteration,order);
- _profile=pflname;
- _localization=locname;
+ MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,type==ON_CELLS?MED_CELL:MED_NODE,type==ON_CELLS?typmai3[(int)geoType]:MED_NONE,MED_COMPACT_PFLMODE,
+ pflname,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast<unsigned char*>(_arr->getPointer()));
+ _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE);
+ _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE);
}
catch(INTERP_KERNEL::Exception& e)
{
return _father->getNumberOfComponents();
}
+int MEDFileFieldPerMeshPerTypePerDisc::getNumberOfTuples() const
+{
+ return _arr->getNumberOfTuples();
+}
+
const std::vector<std::string>& MEDFileFieldPerMeshPerTypePerDisc::getInfos() const
{
return _father->getInfos();
return ret;
}
+bool MEDFileFieldPerMeshPerType::isOnNode(int& type, int& number, const DataArrayInt* &arrs) const throw(INTERP_KERNEL::Exception)
+{
+ if(_type!=ON_NODES)
+ return false;
+ type=INTERP_KERNEL::NORM_ERROR;
+ number=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
+ number+=(*it)->getNumberOfTuples();
+ return true;
+}
+
+bool MEDFileFieldPerMeshPerType::isOnCell(int dimDimReq, int& type, int& number, const DataArrayInt* &arrs) const throw(INTERP_KERNEL::Exception)
+{
+ if(_type!=ON_CELLS)
+ return false;
+ type=(int)_geo_type;
+ number=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerTypePerDisc> >::const_iterator it=_field_pm_pt_pd.begin();it!=_field_pm_pt_pd.end();it++)
+ number+=(*it)->getNumberOfTuples();
+ return true;
+}
+
MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception):_father(fath),_type(type),_geo_type(geoType)
{
}
_field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,fid);
}
-MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time)
+MEDFileFieldPerMesh *MEDFileFieldPerMesh::New(MEDFileField1TSWithoutDAS *fath, double time)
{
- return new MEDFileFieldPerMesh(fath,meshName,time);
+ return new MEDFileFieldPerMesh(fath,time);
}
void MEDFileFieldPerMesh::pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType)
std::string MEDFileFieldPerMesh::getMeshName() const
{
- return _mesh_name;
+ return _father->getMeshName();
}
int MEDFileFieldPerMesh::getNumberOfComponents() const
return ret;
}
-MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time):_father(fath),_mesh_name(meshName),_time(time)
+MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<const DataArrayInt *> arrs;
+ std::vector<int> distrib=getDistributionOfTypes(meshDimRelToMaxExt,mesh->getMeshDimension(),arrs);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=mesh->checkTypeConsistencyAndContig(distrib,arrs);
+ return 0;
+}
+
+std::vector<int> MEDFileFieldPerMesh::getDistributionOfTypes(int meshDimRelToMaxExt, int mdim, std::vector<const DataArrayInt *>& arrs) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt>1)
+ throw INTERP_KERNEL::Exception("Invalid meshDimRelToMaxExt parameter passed ! must be 1 for node and 0,-1,-2,-3 for cells !");
+ std::vector<int> ret;
+ int tmp2,tmp3;
+ arrs.clear();
+ const DataArrayInt *arrTmp=0;
+ if(meshDimRelToMaxExt==1)
+ {//On node
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
+ if((*it)->isOnNode(tmp2,tmp3,arrTmp))
+ {
+ ret.push_back(-1);
+ ret.push_back(tmp2);
+ ret.push_back(tmp3);
+ if(arrTmp)
+ arrs.push_back(arrTmp);
+ }
+ if(ret.size()>2)
+ throw INTERP_KERNEL::Exception("Detected on same time step two different discretization ... Should never happen !");
+ }
+ else
+ {
+ int dimTarget=mdim+meshDimRelToMaxExt;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldPerMeshPerType> >::const_iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++)
+ if((*it)->isOnCell(dimTarget,tmp2,tmp3,arrTmp))
+ {
+ ret.push_back((int)(*it)->getGeoType());
+ ret.push_back(tmp2);
+ ret.push_back(tmp3);
+ if(arrTmp)
+ arrs.push_back(arrTmp);
+ }
+ }
+ if(ret.empty())
+ throw INTERP_KERNEL::Exception("No field part correspond to requested meshdimRel !");
+ return ret;
+}
+
+MEDFileFieldPerMesh::MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, double time):_father(fath),_time(time)
{
}
{
_pfls[id]=DataArrayInt::New();
_pfls[id]->alloc(lgth,1);
- MEDprofilLire(fid,_pfls[id]->getPointer(),(char *)pflName);
+ MEDprofileRd(fid,pflName,_pfls[id]->getPointer());
+ _pfls[id]->applyLin(1,-1,0);//Converting into C format
}
void MEDFieldFieldGlobs::loadProfileInFile(med_idt fid, int i)
{
- INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
int sz;
- MEDprofilInfo(fid,i,pflName,&sz);
+ MEDprofileInfo(fid,i,pflName,&sz);
_pfls[i]=DataArrayInt::New();
_pfls[i]->alloc(sz,1);
- MEDprofilLire(fid,_pfls[i]->getPointer(),(char *)pflName);
+ MEDprofileRd(fid,pflName,_pfls[i]->getPointer());
+}
+
+MEDFieldFieldGlobs::MEDFieldFieldGlobs(const char *fname):_file_name(fname)
+{
+}
+
+void MEDFieldFieldGlobs::setFileName(const char *fileName)
+{
+ _file_name=fileName;
}
std::vector<std::string> MEDFieldFieldGlobs::getPfls() const
return ret;
}
-MEDFileField1TSWithoutDAS *MEDFileField1TSWithoutDAS::New(const char *fieldName, int iteration, int order, const std::vector<std::string>& infos)
+MEDFileField1TSWithoutDAS *MEDFileField1TSWithoutDAS::New(const char *fieldName, const char *meshName, int iteration, int order, int meshIt, int meshOrder, const std::vector<std::string>& infos)
{
- return new MEDFileField1TSWithoutDAS(fieldName,iteration,order,infos);
+ return new MEDFileField1TSWithoutDAS(fieldName,meshName,iteration,order,meshIt,meshOrder,infos);
}
-void MEDFileField1TSWithoutDAS::pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, double time, const char *meshName) const
+void MEDFileField1TSWithoutDAS::pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, double time) const
{
_types.push_back(type);
_geo_types.push_back(geoType);
_times.push_back(time);
- _meshes.push_back(meshName);
}
void MEDFileField1TSWithoutDAS::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception)
{
- std::vector<std::string> meshesOnlyOnce;
- int nbOfTurn=_meshes.size();
- for(int i=0;i<nbOfTurn;i++)
- {
- std::vector<std::string>::iterator it=std::find(meshesOnlyOnce.begin(),meshesOnlyOnce.end(),_meshes[i]);
- if(it==meshesOnlyOnce.end())
- {
- _field_per_mesh.push_back(MEDFileFieldPerMesh::New(this,_meshes[i].c_str(),_times[i]));
- meshesOnlyOnce.push_back(_meshes[i]);
- _field_per_mesh.back()->pushBack(_types[i],_geo_types[i]);
- }
- else
- {
- int w=std::distance(meshesOnlyOnce.begin(),it);
- _field_per_mesh[w]->pushBack(_types[i],_geo_types[i]);
- }
- }
- int nbOfMeshes=_field_per_mesh.size();
- for(int i=0;i<nbOfMeshes;i++)
- _field_per_mesh[i]->finishLoading(fid);
+ _field_per_mesh.push_back(MEDFileFieldPerMesh::New(this,_times[0]));
+ _field_per_mesh[0]->finishLoading(fid);
+}
+
+MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception)
+{
+ MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(glob->getFileName(),_mesh_name.c_str(),_mesh_iteration,_mesh_order);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMaxExt);
+ return _field_per_mesh[0]->getFieldOnMeshAtLevel(meshDimRelToMaxExt,glob,m);
+}
+
+MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception)
+{
+ return _field_per_mesh[0]->getFieldOnMeshAtLevel(meshDimRelToMaxExt,glob,mesh);
}
std::vector<std::string> MEDFileField1TSWithoutDAS::getPflsReallyUsed() const
return ret;
}
-MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS(const char *fieldName, int iteration, int order, const std::vector<std::string>& infos):_name(fieldName),_infos(infos),_iteration(iteration),_order(order)
+MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS(const char *fieldName, const char *meshName, int iteration, int order, int meshIt, int meshOrder,
+ const std::vector<std::string>& infos):_name(fieldName),_mesh_name(meshName),_infos(infos),_iteration(iteration),_order(order),
+ _mesh_iteration(meshIt),_mesh_order(meshOrder)
{
}
}
MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
-try:MEDFileField1TSWithoutDAS(fieldName,iteration,order,std::vector<std::string>())
+try:MEDFileField1TSWithoutDAS(fieldName,"",iteration,order,-1,-1,std::vector<std::string>()),MEDFieldFieldGlobs(fileName)
{
MEDFileUtilities::CheckFileForRead(fileName);
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- int nbFields=MEDnChamp(fid,0);
- med_type_champ typcha;
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ int nbFields=MEDnField(fid);
+ med_field_type typcha;
bool found=false;
std::vector<std::string> fns(nbFields);
for(int i=0;i<nbFields && !found;i++)
{
- int ncomp=MEDnChamp(fid,i+1);
- INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_TAILLE_PNOM+1];
- INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_TAILLE_PNOM+1];
- INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
+ int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_bool localMesh;
+ int nbOfStep;
+ MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
std::string tmp(nomcha);
fns[i]=tmp;
found=(tmp==fieldName);
if(found)
{
+ std::string mname=MEDLoaderBase::buildStringFromFortran(nomMaa,MED_NAME_SIZE);
+ _mesh_name=mname;
_infos.resize(ncomp);
for(int j=0;j<ncomp;j++)
- _infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM,(char *)unit+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
+ _infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+i*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
}
}
if(!found)
_pfls.resize(sz);
for(int i=0;i<sz;i++)
loadProfileInFile(fid,i,profiles[i].c_str(),37);//tony
- MEDfermer(fid);
}
catch(INTERP_KERNEL::Exception& e)
{
throw e;
}
-MEDFileFieldMultiTSWithoutDAS *MEDFileFieldMultiTSWithoutDAS::New(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
+MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ return MEDFileField1TSWithoutDAS::getFieldAtLevel(meshDimRelToMaxExt,this);
+}
+
+MEDCouplingFieldDouble *MEDFileField1TS::getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception)
+{
+ return MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(meshDimRelToMaxExt,this,mesh);
+}
+
+MEDFileFieldMultiTSWithoutDAS *MEDFileFieldMultiTSWithoutDAS::New(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception)
{
- return new MEDFileFieldMultiTSWithoutDAS(fid,fieldName,id,infos);
+ return new MEDFileFieldMultiTSWithoutDAS(fid,fieldName,id,infos,nbOfStep);
}
MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(const char *fieldName):_name(fieldName)
{
}
-MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception)
+MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception)
try:_name(fieldName),_infos(infos)
{
- finishLoading(fid);
+ finishLoading(fid,nbOfStep);
}
catch(INTERP_KERNEL::Exception& e)
{
throw e;
}
-void MEDFileFieldMultiTSWithoutDAS::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception)
+void MEDFileFieldMultiTSWithoutDAS::finishLoading(med_idt fid, int nbPdt) throw(INTERP_KERNEL::Exception)
{
- for(int i=0;i<MED_NBR_GEOMETRIE_MAILLE+2;i++)
- {
- int nbPdt=MEDnPasdetemps(fid,(char *)_name.c_str(),MED_MAILLE,typmai[i]);
- for(int j=0;j<nbPdt;j++)
- appendTimeStepEntry(fid,MED_MAILLE,i,j);
- }
- int nbPdt=MEDnPasdetemps(fid,(char *)_name.c_str(),MED_NOEUD,MED_NONE);
+ for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
+ for(int j=0;j<nbPdt;j++)
+ appendTimeStepEntry(fid,MED_CELL,i,j);
for(int j=0;j<nbPdt;j++)
- appendTimeStepEntry(fid,MED_NOEUD,0,j);
+ appendTimeStepEntry(fid,MED_NODE,0,j);
int nbOfTimeSteps=_time_steps.size();
for(int i=0;i<nbOfTimeSteps;i++)
_time_steps[i]->finishLoading(fid);
}
-void MEDFileFieldMultiTSWithoutDAS::appendTimeStepEntry(med_idt fid, med_entite_maillage entity, int i, int j) throw(INTERP_KERNEL::Exception)
+void MEDFileFieldMultiTSWithoutDAS::appendTimeStepEntry(med_idt fid, med_entity_type entity, int i, int j) throw(INTERP_KERNEL::Exception)
{
std::vector< std::pair<int,int> > ts;
- med_int ngauss=0;
- med_int numdt=0,numo=0,nbrefmaa;
+ med_int numdt=0,numo=0;
+ med_int meshIt=0,meshOrder=0;
med_float dt=0.0;
- med_booleen local;
- INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
- MEDpasdetempsInfo(fid,(char *)_name.c_str(),MED_MAILLE,typmai[i],j+1,&ngauss,&numdt,&numo,dt_unit,&dt,maa_ass,&local,&nbrefmaa);
+ MEDfieldComputingStepMeshInfo(fid,_name.c_str(),j+1,&numdt,&numo,&dt,&meshIt,&meshOrder);
std::pair<int,int> p(numdt,numo);
std::vector< std::pair<int,int> >::iterator where=std::find(ts.begin(),ts.end(),p);
if(where==ts.end())
{
ts.push_back(p);
- _time_steps.push_back(MEDFileField1TSWithoutDAS::New(_name.c_str(),numdt,numo,_infos));
- _time_steps.back()->pushBack(entity==MED_MAILLE?ON_CELLS:ON_NODES,entity==MED_MAILLE?typmai2[i]:INTERP_KERNEL::NORM_ERROR,dt,maa_ass);
+ _time_steps.push_back(MEDFileField1TSWithoutDAS::New(_name.c_str(),_mesh_name.c_str(),numdt,numo,meshIt,meshOrder,_infos));
+ _time_steps.back()->pushBack(entity==MED_CELL?ON_CELLS:ON_NODES,entity==MED_CELL?typmai2[i]:INTERP_KERNEL::NORM_ERROR,dt);
}
else
{
int w=std::distance(ts.begin(),where);
- _time_steps[w]->pushBack(entity==MED_MAILLE?ON_CELLS:ON_NODES,entity==MED_MAILLE?typmai2[i]:INTERP_KERNEL::NORM_ERROR,dt,maa_ass);
+ _time_steps[w]->pushBack(entity==MED_CELL?ON_CELLS:ON_NODES,entity==MED_CELL?typmai2[i]:INTERP_KERNEL::NORM_ERROR,dt);
}
}
return ret;
}
+int MEDFileFieldMultiTSWithoutDAS::getNumberOfTS() const
+{
+ return _time_steps.size();
+}
+
MEDFileFieldMultiTS *MEDFileFieldMultiTS::New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
{
return new MEDFileFieldMultiTS(fileName,fieldName);
}
MEDFileFieldMultiTS::MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
-try:MEDFileFieldMultiTSWithoutDAS(fieldName)
+try:MEDFileFieldMultiTSWithoutDAS(fieldName),MEDFieldFieldGlobs(fileName)
{
MEDFileUtilities::CheckFileForRead(fileName);
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- int nbFields=MEDnChamp(fid,0);
- med_type_champ typcha;
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ int nbFields=MEDnField(fid);
+ med_field_type typcha;
bool found=false;
std::vector<std::string> fns(nbFields);
+ int nbstep2=-1;
for(int i=0;i<nbFields && !found;i++)
{
- int ncomp=MEDnChamp(fid,i+1);
- INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_TAILLE_PNOM+1];
- INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_TAILLE_PNOM+1];
- INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
+ int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_bool localMesh;
+ int nbOfStep;
+ MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
std::string tmp(nomcha);
fns[i]=tmp;
found=(tmp==fieldName);
if(found)
{
+ nbstep2=nbOfStep;
_infos.resize(ncomp);
for(int j=0;j<ncomp;j++)
- _infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM,(char *)unit+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
+ _infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+i*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
}
}
if(!found)
std::copy(fns.begin(),fns.end(),std::ostream_iterator<std::string>(oss," "));
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- finishLoading(fid);
- MEDfermer(fid);
+ finishLoading(fid,nbstep2);
}
catch(INTERP_KERNEL::Exception& e)
{
}
MEDFileFields::MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception)
-try
+try:MEDFieldFieldGlobs(fileName)
{
MEDFileUtilities::CheckFileForRead(fileName);
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- int nbFields=MEDnChamp(fid,0);
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ int nbFields=MEDnField(fid);
_fields.resize(nbFields);
- med_type_champ typcha;
+ med_field_type typcha;
for(int i=0;i<nbFields;i++)
{
- int ncomp=MEDnChamp(fid,i+1);
- INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_TAILLE_PNOM+1];
- INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_TAILLE_PNOM+1];
- INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
+ int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomMaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_bool localMesh;
+ int nbOfStep;
+ MEDfieldInfo(fid,i+1,nomcha,nomMaa,&localMesh,&typcha,comp,unit,dtunit,&nbOfStep);
std::vector<std::string> infos(ncomp);
for(int j=0;j<ncomp;j++)
- infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM,(char *)unit+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
- _fields[i]=MEDFileFieldMultiTSWithoutDAS::New(fid,nomcha,i,infos);
+ infos[j]=MEDLoaderBase::buildUnionUnit((char *)comp+i*MED_SNAME_SIZE,MED_SNAME_SIZE,(char *)unit+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
+ _fields[i]=MEDFileFieldMultiTSWithoutDAS::New(fid,nomcha,i,infos,nbOfStep);
}
- int nProfil=MEDnProfil(fid);
+ int nProfil=MEDnProfile(fid);
_pfls.resize(nProfil);
for(int i=0;i<nProfil;i++)
loadProfileInFile(fid,i);
- MEDfermer(fid);
}
catch(INTERP_KERNEL::Exception& e)
{
namespace ParaMEDMEM
{
+ class MEDFieldFieldGlobs;
+ class MEDCouplingMesh;
+ class MEDCouplingFieldDouble;
+
class MEDFileFieldLoc : public RefCountObject
{
public:
TypeOfField getType() const;
INTERP_KERNEL::NormalizedCellType getGeoType() const;
int getNumberOfComponents() const;
+ int getNumberOfTuples() const;
const std::vector<std::string>& getInfos() const;
std::string getProfile() const;
std::string getLocalization() const;
private:
MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, med_idt fid) throw(INTERP_KERNEL::Exception);
+
private:
MEDFileFieldPerMeshPerType *_father;
MEDCouplingAutoRefCountObjectPtr< DataArrayDouble > _arr;
const std::vector<std::string>& getInfos() const;
std::vector<std::string> getPflsReallyUsed() const;
std::vector<std::string> getLocsReallyUsed() const;
+ bool isOnNode(int& type, int& number, const DataArrayInt* &arrs) const throw(INTERP_KERNEL::Exception);
+ bool isOnCell(int dimDimReq, int& type, int& number, const DataArrayInt* &arrs) const throw(INTERP_KERNEL::Exception);
private:
MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception);
private:
class MEDFileFieldPerMesh : public RefCountObject
{
public:
- static MEDFileFieldPerMesh *New(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time);
+ static MEDFileFieldPerMesh *New(MEDFileField1TSWithoutDAS *fath, double time);
void pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType);
void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception);
double getTime() const;
const std::vector<std::string>& getInfos() const;
std::vector<std::string> getPflsReallyUsed() const;
std::vector<std::string> getLocsReallyUsed() const;
+ std::vector<int> getDistributionOfTypes(int meshDimRelToMaxExt, int mdim, std::vector<const DataArrayInt *>& arrs) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldDouble *getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception);
private:
- MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, const char *meshName, double time);
+ MEDFileFieldPerMesh(MEDFileField1TSWithoutDAS *fath, double time);
private:
MEDFileField1TSWithoutDAS *_father;
std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > > _field_pm_pt;
- std::string _mesh_name;
double _time;
private:
mutable std::vector<TypeOfField> _types;
class MEDFieldFieldGlobs
{
public:
+ MEDFieldFieldGlobs(const char *fname);
void loadProfileInFile(med_idt fid, int id, const char *pflName, int lgth) throw(INTERP_KERNEL::Exception);
void loadProfileInFile(med_idt fid, int id);
std::vector<std::string> getPfls() const;
std::vector<std::string> getLocs() const;
+ void setFileName(const char *fileName);
+ const char *getFileName() const { return _file_name.c_str(); }
protected:
std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > _pfls;
std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> > _locs;
+ std::string _file_name;
};
class MEDFileField1TSWithoutDAS : public RefCountObject
{
public:
- static MEDFileField1TSWithoutDAS *New(const char *fieldName, int iteration, int order, const std::vector<std::string>& infos);
- void pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, double time, const char *meshName) const;
- void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception);
int getIteration() const { return _iteration; }
int getOrder() const { return _order; }
std::string getName() const { return _name; }
+ std::string getMeshName() const { return _mesh_name; }
int getNumberOfComponents() const { return _infos.size(); }
const std::vector<std::string>& getInfos() const { return _infos; }
std::vector<std::string> getPflsReallyUsed() const;
std::vector<std::string> getLocsReallyUsed() const;
+ //
+ static MEDFileField1TSWithoutDAS *New(const char *fieldName, const char *meshName, int iteration, int order, int meshIt, int meshOrder, const std::vector<std::string>& infos);
+ void pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, double time) const;
+ void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception);
+ protected:
+ MEDCouplingFieldDouble *getFieldAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldDouble *getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception);
protected:
- MEDFileField1TSWithoutDAS(const char *fieldName, int iteration, int order, const std::vector<std::string>& infos);
+ MEDFileField1TSWithoutDAS(const char *fieldName, const char *meshName, int iteration, int order, int meshIt, int meshOrder,
+ const std::vector<std::string>& infos);
protected:
std::string _name;
+ std::string _mesh_name;
std::vector<std::string> _infos;
std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > > _field_per_mesh;
int _iteration;
int _order;
+ int _mesh_iteration;
+ int _mesh_order;
private:
mutable std::vector<TypeOfField> _types;
mutable std::vector<INTERP_KERNEL::NormalizedCellType> _geo_types;
mutable std::vector<double> _times;
- mutable std::vector<std::string> _meshes;
};
/*!
{
public:
static MEDFileField1TS *New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception);
+ void setFileName(const char *fileName);
+ MEDCouplingFieldDouble *getFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingFieldDouble *getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception);
private:
MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception);
};
class MEDFileFieldMultiTSWithoutDAS : public RefCountObject
{
public:
- static MEDFileFieldMultiTSWithoutDAS *New(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception);
+ static MEDFileFieldMultiTSWithoutDAS *New(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception);
+ int getNumberOfTS() const;
protected:
MEDFileFieldMultiTSWithoutDAS(const char *fieldName);
- MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception);
- void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception);
- void appendTimeStepEntry(med_idt fid, med_entite_maillage entity, int i, int j) throw(INTERP_KERNEL::Exception);
+ MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector<std::string>& infos, int nbOfStep) throw(INTERP_KERNEL::Exception);
+ void finishLoading(med_idt fid, int nbPdt) throw(INTERP_KERNEL::Exception);
+ void appendTimeStepEntry(med_idt fid, med_entity_type entity, int i, int j) throw(INTERP_KERNEL::Exception);
std::vector<std::string> getPflsReallyUsed() const;
std::vector<std::string> getLocsReallyUsed() const;
protected:
std::string _name;
+ std::string _mesh_name;
std::vector<std::string> _infos;
std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSWithoutDAS> > _time_steps;
};
public:
static MEDFileFields *New(const char *fileName) throw(INTERP_KERNEL::Exception);
int getNumberOfFields() const;
- std::vector<std::string> getPfls() const;
- std::vector<std::string> getLocs() const;
private:
MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception);
private:
#include "InterpKernelAutoPtr.hxx"
#include <limits>
+#include <cmath>
using namespace ParaMEDMEM;
-MEDFileMesh *MEDFileMesh::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
-{
- throw INTERP_KERNEL::Exception("Not implemented yet !");
-}
+const char MEDFileMesh::DFT_FAM_NAME[]="FAMILLE_ZERO";
-MEDFileUMesh *MEDFileUMesh::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
+MEDFileMesh::MEDFileMesh():_order(-1),_iteration(-1),_time(0.),_too_long_str(0),_zipconn_pol(2)
{
- return new MEDFileUMesh(fileName,mName);
}
-MEDFileUMesh *MEDFileUMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
+MEDFileMesh *MEDFileMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
{
std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
if(ms.empty())
{
- std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
+ std::ostringstream oss; oss << "MEDFileMesh::New : no meshes in file \"" << fileName << "\" !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- return new MEDFileUMesh(fileName,ms.front().c_str());
-}
-
-MEDFileUMesh *MEDFileUMesh::New()
-{
- return new MEDFileUMesh;
-}
-
-MEDFileUMesh::MEDFileUMesh():_too_long_str(0),_zipconn_pol(2)
-{
-}
-
-MEDFileUMesh::MEDFileUMesh(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
- try:_too_long_str(0)
- {
- MEDFileUtilities::CheckFileForRead(fileName);
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- MEDFileUMeshL2 loaderl2;
- loaderl2.loadAll(fid,MEDFileUMeshL2::getMeshIdFromName(fid,mName),mName);
- int lev=loaderl2.getNumberOfLevels();
- _ms.resize(lev);
- for(int i=0;i<lev;i++)
- {
- if(!loaderl2.emptyLev(i))
- _ms[i]=new MEDFileUMeshSplitL1(loaderl2,mName,i);
- else
- _ms[i]=0;
- }
- MEDFileUMeshL2::readFamiliesAndGrps(fid,mName,_families,_groups);
- MEDfermer(fid);
- //
- setName(loaderl2.getName());
- setDescription(loaderl2.getDescription());
- _coords=loaderl2.getCoords();
- _fam_coords=loaderl2.getCoordsFamily();
- _num_coords=loaderl2.getCoordsNum();
- computeRevNum();
- }
-catch(INTERP_KERNEL::Exception& e)
- {
- throw e;
- }
-
-MEDFileUMesh::~MEDFileUMesh()
-{
-}
-
-void MEDFileUMesh::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
-{
- if(_name.empty())
- throw INTERP_KERNEL::Exception("MEDFileUMesh : name is empty. MED file ask for a NON EMPTY name !");
- if(!existsFamily(0))
- (const_cast<MEDFileUMesh *>(this))->addFamily(0,"FAMILLE_ZERO");
- med_mode_acces medmod=MEDFileUtilities::TraduceWriteMode(mode);
- med_idt fid=MEDouvrir((char *)fileName,medmod);
- std::ostringstream oss; oss << "MEDFileUMesh : error on attempt to write in file : \"" << fileName << "\"";
- MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
- const DataArrayDouble *coo=_coords;
- INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_TAILLE_DESC);
- MEDLoaderBase::safeStrCpy(_name.c_str(),MED_TAILLE_NOM,maa,_too_long_str);
- MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_TAILLE_DESC,desc,_too_long_str);
- int spaceDim=coo?coo->getNumberOfComponents():0;
- int mdim=getMeshDimension();
- MEDmaaCr(fid,maa,spaceDim,MED_NON_STRUCTURE,desc);//spaceDim is false but to make reader happy for 3DSurf and 2DCurve meshes !
- MEDdimEspaceCr(fid,maa,spaceDim);
- MEDFileUMeshL2::writeCoords(fid,maa,_coords,_fam_coords,_num_coords);
- for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
- if((const MEDFileUMeshSplitL1 *)(*it)!=0)
- (*it)->write(fid,maa,mdim);
- MEDFileUMeshL2::writeFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str);
- MEDfermer(fid);
-}
-
-std::vector<int> MEDFileUMesh::getNonEmptyLevels() const
-{
- std::vector<int> ret;
- int lev=0;
- for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--)
- if((const MEDFileUMeshSplitL1 *)(*it)!=0)
- if(!(*it)->empty())
- ret.push_back(lev);
- return ret;
-}
-
-std::vector<int> MEDFileUMesh::getNonEmptyLevelsExt() const
-{
- std::vector<int> ret0=getNonEmptyLevels();
- if((const DataArrayDouble *) _coords)
+ MEDFileUtilities::CheckFileForRead(fileName);
+ ParaMEDMEM::MEDCouplingMeshType meshType;
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ int dt,it;
+ std::string dummy2;
+ MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
+ switch(meshType)
{
- std::vector<int> ret(ret0.size()+1);
- ret[0]=1;
- std::copy(ret0.begin(),ret0.end(),ret.begin()+1);
- return ret;
+ case UNSTRUCTURED:
+ {
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=MEDFileUMesh::New();
+ ret->loadUMeshFromFile(fid,ms.front().c_str(),dt,it);
+ ret->incrRef();
+ return (MEDFileUMesh *)ret;
+ }
+ case CARTESIAN:
+ {
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=MEDFileCMesh::New();
+ ret->loadCMeshFromFile(fid,ms.front().c_str(),dt,it);
+ ret->incrRef();
+ return (MEDFileCMesh *)ret;
+ }
+ default:
+ {
+ std::ostringstream oss; oss << "MEDFileMesh::New : MED file exists and has mesh '" << ms.front() << "' exists but unsupported type yet !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
}
- return ret0;
}
-int MEDFileUMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception)
+MEDFileMesh *MEDFileMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
{
- std::string oname(name);
- std::map<std::string, int>::const_iterator it=_families.find(oname);
- std::vector<std::string> fams=getFamiliesNames();
- if(it==_families.end())
+ MEDFileUtilities::CheckFileForRead(fileName);
+ ParaMEDMEM::MEDCouplingMeshType meshType;
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ int dummy0,dummy1;
+ std::string dummy2;
+ MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2);
+ switch(meshType)
{
- std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :";
- std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
- throw INTERP_KERNEL::Exception(oss.str().c_str());
+ case UNSTRUCTURED:
+ {
+ MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=MEDFileUMesh::New();
+ ret->loadUMeshFromFile(fid,mName,dt,it);
+ ret->incrRef();
+ return (MEDFileUMesh *)ret;
+ }
+ case CARTESIAN:
+ {
+ MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=MEDFileCMesh::New();
+ ret->loadCMeshFromFile(fid,mName,dt,it);
+ ret->incrRef();
+ return (MEDFileCMesh *)ret;
+ }
+ default:
+ {
+ std::ostringstream oss; oss << "MEDFileMesh::New : MED file exists and has mesh '" << mName << "' exists but unsupported type yet !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
}
- return (*it).second;
}
-int MEDFileUMesh::getMaxFamilyId() const throw(INTERP_KERNEL::Exception)
+bool MEDFileMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
{
- if(_families.empty())
- throw INTERP_KERNEL::Exception("MEDFileUMesh::getMaxFamilyId : no families set !");
- int ret=-std::numeric_limits<int>::max();
- for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
+ if(_order!=other->_order)
{
- ret=std::max((*it).second,ret);
+ what="Orders differ !";
+ return false;
}
- return ret;
-}
-
-std::vector<int> MEDFileUMesh::getFamiliesIds(const std::vector<std::string>& famNames) const throw(INTERP_KERNEL::Exception)
-{
- std::vector<int> famIds;
- for(std::vector<std::string>::const_iterator it=famNames.begin();it!=famNames.end();it++)
+ if(_iteration!=other->_iteration)
{
- std::map<std::string,int>::const_iterator it2=_families.find(*it);
- if(it2==_families.end())
- {
- std::ostringstream oss; oss << "No such family in mesh \"" << _name << "\" : " << *it;
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- famIds.push_back((*it2).second);
+ what="Iterations differ !";
+ return false;
}
- return famIds;
-}
-
-std::string MEDFileUMesh::getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception)
-{
- for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
- if((*it).second==id)
- return (*it).first;
- std::ostringstream oss; oss << "MEDFileUMesh::getFamilyNameGivenId : no such family id : " << id;
- throw INTERP_KERNEL::Exception(oss.str().c_str());
-}
-
-int MEDFileUMesh::getMeshDimension() const
-{
- int lev=0;
- for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev++)
- if((const MEDFileUMeshSplitL1 *)(*it)!=0)
- return (*it)->getMeshDimension()+lev;
- throw INTERP_KERNEL::Exception("MEDFileUMesh::getMeshDimension : impossible to find a mesh dimension !");
-}
-
-int MEDFileUMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
-{
- if(meshDimRelToMaxExt==1)
+ if(fabs(_time-other->_time)>eps)
{
- if(!((const DataArrayDouble *)_coords))
- throw INTERP_KERNEL::Exception("MEDFileUMesh::getSizeAtLevel : no coordinates specified !");
- return _coords->getNumberOfTuples();
+ what="Time values differ !";
+ return false;
}
- return getMeshAtLevSafe(meshDimRelToMaxExt)->getSize();
-}
-
-const DataArrayInt *MEDFileUMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
-{
- if(meshDimRelToMaxExt==1)
+ if(_dt_unit!=other->_dt_unit)
{
- if(!((const DataArrayInt *)_fam_coords))
- throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamilyFieldAtLevel : no coordinates specified !");
- return _fam_coords;
+ what="Time units differ !";
+ return false;
}
- const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
- return l1->getFamilyField();
+ if(_name!=other->_name)
+ {
+ what="Names differ !";
+ return false;
+ }
+ if(_univ_name!=other->_univ_name)
+ {
+ what="Univ names differ !";
+ return false;
+ }
+ if(_desc_name!=other->_desc_name)
+ {
+ what="Description names differ !";
+ return false;
+ }
+ if(!areGrpsEqual(other,what))
+ return false;
+ if(!areFamsEqual(other,what))
+ return false;
+ return true;
}
-const DataArrayInt *MEDFileUMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+void MEDFileMesh::clearNonDiscrAttributes() const
{
- if(meshDimRelToMaxExt==1)
- {
- if(!((const DataArrayInt *)_num_coords))
- throw INTERP_KERNEL::Exception("MEDFileUMesh::getNumberFieldAtLevel : no coordinates renum specified !");
- return _num_coords;
- }
- const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
- return l1->getNumberField();
+
}
-const DataArrayInt *MEDFileUMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+void MEDFileMesh::copyFamGrpMapsFrom(const MEDFileMesh& other)
{
- if(meshDimRelToMaxExt==1)
- {
- if(!((const DataArrayInt *)_num_coords))
- throw INTERP_KERNEL::Exception("MEDFileUMesh::getRevNumberFieldAtLevel : no coordinates renum specified !");
- return _rev_num_coords;
- }
- const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
- return l1->getRevNumberField();
+ _groups=other._groups;
+ _families=other._families;
}
-std::vector<std::string> MEDFileUMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception)
+std::vector<std::string> MEDFileMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception)
{
std::string oname(name);
std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.find(oname);
return (*it).second;
}
-std::vector<std::string> MEDFileUMesh::getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception)
+std::vector<std::string> MEDFileMesh::getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception)
{
std::vector<std::string> ret;
for(std::map<std::string, std::vector<std::string> >::const_iterator it1=_groups.begin();it1!=_groups.end();it1++)
return ret;
}
-std::vector<std::string> MEDFileUMesh::getGroupsNames() const
+std::vector<std::string> MEDFileMesh::getGroupsNames() const
{
std::vector<std::string> ret(_groups.size());
int i=0;
return ret;
}
-std::vector<std::string> MEDFileUMesh::getFamiliesNames() const
+std::vector<std::string> MEDFileMesh::getFamiliesNames() const
{
std::vector<std::string> ret(_families.size());
int i=0;
return ret;
}
-void MEDFileUMesh::removeGroup(const char *name) throw(INTERP_KERNEL::Exception)
+void MEDFileMesh::removeGroup(const char *name) throw(INTERP_KERNEL::Exception)
{
std::string oname(name);
std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
_groups.erase(it);
}
-void MEDFileUMesh::removeFamily(const char *name) throw(INTERP_KERNEL::Exception)
+void MEDFileMesh::removeFamily(const char *name) throw(INTERP_KERNEL::Exception)
{
std::string oname(name);
std::map<std::string, int >::iterator it=_families.find(oname);
_families.erase(it);
}
-void MEDFileUMesh::changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
+void MEDFileMesh::changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
{
std::string oname(oldName);
std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
it=_groups.find(nname);
if(it!=_groups.end())
{
- std::ostringstream oss; oss << "Such groupname \"" << newName << " already exists ! Kill it before !";
+ std::ostringstream oss; oss << "Such groupname \"" << newName << "\" already exists ! Kill it before !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
std::vector<std::string> cpy=(*it).second;
_groups[newName]=cpy;
}
-void MEDFileUMesh::changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
+void MEDFileMesh::changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
{
std::string oname(oldName);
std::map<std::string, int >::iterator it=_families.find(oname);
_families[newName]=cpy;
}
-DataArrayDouble *MEDFileUMesh::getCoords() const
+bool MEDFileMesh::areFamsEqual(const MEDFileMesh *other, std::string& what) const
{
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(_coords);
- if((DataArrayDouble *)tmp)
+ if(_families==other->_families)
+ return true;
+ std::map<std::string,int> fam0;
+ std::map<std::string,int> fam1;
+ for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
+ if((*it).second!=0)
+ fam0[(*it).first]=(*it).second;
+ for(std::map<std::string,int>::const_iterator it=other->_families.begin();it!=other->_families.end();it++)
+ if((*it).second!=0)
+ fam1[(*it).first]=(*it).second;
+ return fam0==fam1;
+}
+
+bool MEDFileMesh::areGrpsEqual(const MEDFileMesh *other, std::string& what) const
+{
+ if(_groups==other->_groups)
+ return true;
+ bool ret=true;
+ std::size_t sz=_groups.size();
+ if(sz!=other->_groups.size())
{
- tmp->incrRef();
- return tmp;
+ what="Groups differ because not same number !\n";
+ ret=false;
}
- return 0;
+ if(ret)
+ {
+ std::map<std::string, std::vector<std::string> >::const_iterator it1=_groups.begin();
+ for(std::size_t i=0;i<sz && ret;i++,it1++)
+ {
+ std::map<std::string, std::vector<std::string> >::const_iterator it2=other->_groups.find((*it1).first);
+ if(it2!=other->_groups.end())
+ {
+ std::set<std::string> s1((*it1).second.begin(),(*it1).second.end());
+ std::set<std::string> s2((*it2).second.begin(),(*it2).second.end());
+ ret=(s1==s2);
+ }
+ else
+ {
+ ret=false;
+ what="A group in first mesh exists not in other !\n";
+ }
+ }
+ }
+ if(!ret)
+ {
+ std::ostringstream oss; oss << "Groups description differs :\n";
+ oss << "First group description :\n";
+ for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++)
+ {
+ oss << " Group \"" << (*it).first << "\" on following families :\n";
+ for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
+ oss << " \"" << *it2 << "\n";
+ }
+ oss << "Second group description :\n";
+ for(std::map<std::string, std::vector<std::string> >::const_iterator it=other->_groups.begin();it!=other->_groups.end();it++)
+ {
+ oss << " Group \"" << (*it).first << "\" on following families :\n";
+ for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
+ oss << " \"" << *it2 << "\n";
+ }
+ what+=oss.str();
+ }
+ return ret;
}
-MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
+bool MEDFileMesh::existsFamily(int famId) const
{
- std::vector<std::string> tmp(1);
- tmp[0]=grp;
- MEDCouplingUMesh *ret=getGroups(meshDimRelToMaxExt,tmp,renum);
- ret->setName(grp);
- return ret;
+ for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
+ if((*it2).second==famId)
+ return true;
+ return false;
}
-DataArrayInt *MEDFileUMesh::getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
+bool MEDFileMesh::existsFamily(const char *familyName) const
{
- std::vector<std::string> tmp(1);
- tmp[0]=grp;
- DataArrayInt *ret=getGroupsArr(meshDimRelToMaxExt,tmp,renum);
- ret->setName(grp);
- return ret;
+ std::string fname(familyName);
+ return _families.find(fname)!=_families.end();
}
-MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
+void MEDFileMesh::setFamilyId(const char *familyName, int id)
{
- std::set<std::string> fams;
- for(std::vector<std::string>::const_iterator it=grps.begin();it!=grps.end();it++)
+ std::string fname(familyName);
+ _families[fname]=id;
+}
+
+/*!
+ * This method appends a new entry in _families attribute. An exception is thrown if either the famId is already
+ * kept by an another familyName. An exception is thrown if name 'familyName' is alreadyset with a different 'famId'.
+ */
+void MEDFileMesh::addFamily(const char *familyName, int famId) throw(INTERP_KERNEL::Exception)
+{
+ std::string fname(familyName);
+ std::map<std::string,int>::const_iterator it=_families.find(fname);
+ if(it==_families.end())
{
- std::map<std::string, std::vector<std::string> >::const_iterator it2=_groups.find(*it);
- if(it2==_groups.end())
+ for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
+ if((*it2).second==famId)
+ {
+ std::ostringstream oss;
+ oss << "MEDFileMesh::addFamily : Family \"" << (*it2).first << "\" already exists with specified id : " << famId << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ _families[fname]=famId;
+ }
+ else
+ {
+ if((*it).second!=famId)
{
- std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it;
+ std::ostringstream oss;
+ oss << "MEDFileMesh::addFamily : Family \"" << fname << "\" already exists but has id set to " << (*it).second << " different from asked famId " << famId << " !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- fams.insert((*it2).second.begin(),(*it2).second.end());
}
- std::vector<std::string> fams2(fams.begin(),fams.end());
- return getFamilies(meshDimRelToMaxExt,fams2,renum);
}
-DataArrayInt *MEDFileUMesh::getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
+void MEDFileMesh::addGrpOnFamily(const char *grpName, const char *famName) throw(INTERP_KERNEL::Exception)
{
- std::set<std::string> fams;
- for(std::vector<std::string>::const_iterator it=grps.begin();it!=grps.end();it++)
+ std::string grpn(grpName);
+ std::string famn(famName);
+ if(grpn.empty() || famn.empty())
+ throw INTERP_KERNEL::Exception("MEDFileMesh::addGrpOnFamily : input strings must be non null !");
+ std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(grpn);
+ if(it==_groups.end())
{
- std::map<std::string, std::vector<std::string> >::const_iterator it2=_groups.find(*it);
- if(it2==_groups.end())
- {
- std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it;
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- fams.insert((*it2).second.begin(),(*it2).second.end());
+ _groups[grpn].push_back(famn);
+ }
+ else
+ {
+ std::vector<std::string>::iterator it2=std::find((*it).second.begin(),(*it).second.end(),famn);
+ if(it2==(*it).second.end())
+ (*it).second.push_back(famn);
}
- std::vector<std::string> fams2(fams.begin(),fams.end());
- return getFamiliesArr(meshDimRelToMaxExt,fams2,renum);
}
-MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
+void MEDFileMesh::setFamilyInfo(const std::map<std::string,int>& info)
{
- std::vector<std::string> tmp(1);
- tmp[0]=fam;
- MEDCouplingUMesh *ret=getFamilies(meshDimRelToMaxExt,tmp,renum);
- ret->setName(fam);
- return ret;
+ _families=info;
}
-DataArrayInt *MEDFileUMesh::getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
+void MEDFileMesh::setGroupInfo(const std::map<std::string, std::vector<std::string> >&info)
{
- std::vector<std::string> tmp(1);
- tmp[0]=fam;
- DataArrayInt *ret=getFamiliesArr(meshDimRelToMaxExt,tmp,renum);
- ret->setName(fam);
- return ret;
+ _groups=info;
}
-MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
+int MEDFileMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception)
{
- if(meshDimRelToMaxExt==1)
+ std::string oname(name);
+ std::map<std::string, int>::const_iterator it=_families.find(oname);
+ std::vector<std::string> fams=getFamiliesNames();
+ if(it==_families.end())
{
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=getFamiliesArr(1,fams,renum);
- MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New();
- MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> c=_coords->selectByTupleId(arr->getConstPointer(),arr->getConstPointer()+arr->getNbOfElems());
- ret->setCoords(c);
- ret->incrRef();
+ std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :";
+ std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return (*it).second;
+}
+
+int MEDFileMesh::getMaxFamilyId() const throw(INTERP_KERNEL::Exception)
+{
+ if(_families.empty())
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getMaxFamilyId : no families set !");
+ int ret=-std::numeric_limits<int>::max();
+ for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
+ {
+ ret=std::max((*it).second,ret);
+ }
+ return ret;
+}
+
+std::vector<int> MEDFileMesh::getFamiliesIds(const std::vector<std::string>& famNames) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<int> famIds;
+ for(std::vector<std::string>::const_iterator it=famNames.begin();it!=famNames.end();it++)
+ {
+ std::map<std::string,int>::const_iterator it2=_families.find(*it);
+ if(it2==_families.end())
+ {
+ std::ostringstream oss; oss << "No such family in mesh \"" << _name << "\" : " << *it;
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ famIds.push_back((*it2).second);
+ }
+ return famIds;
+}
+
+std::string MEDFileMesh::getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception)
+{
+ for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
+ if((*it).second==id)
+ return (*it).first;
+ std::ostringstream oss; oss << "MEDFileUMesh::getFamilyNameGivenId : no such family id : " << id;
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+}
+
+DataArrayInt *MEDFileMesh::getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> tmp(1);
+ tmp[0]=grp;
+ DataArrayInt *ret=getGroupsArr(meshDimRelToMaxExt,tmp,renum);
+ ret->setName(grp);
+ return ret;
+}
+
+DataArrayInt *MEDFileMesh::getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ std::set<std::string> fams;
+ for(std::vector<std::string>::const_iterator it=grps.begin();it!=grps.end();it++)
+ {
+ std::map<std::string, std::vector<std::string> >::const_iterator it2=_groups.find(*it);
+ if(it2==_groups.end())
+ {
+ std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it;
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ fams.insert((*it2).second.begin(),(*it2).second.end());
+ }
+ std::vector<std::string> fams2(fams.begin(),fams.end());
+ return getFamiliesArr(meshDimRelToMaxExt,fams2,renum);
+}
+
+DataArrayInt *MEDFileMesh::getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> tmp(1);
+ tmp[0]=fam;
+ DataArrayInt *ret=getFamiliesArr(meshDimRelToMaxExt,tmp,renum);
+ ret->setName(fam);
+ return ret;
+}
+
+DataArrayInt *MEDFileMesh::getNodeGroupArr(const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> tmp(1);
+ tmp[0]=grp;
+ DataArrayInt *ret=getNodeGroupsArr(tmp,renum);
+ ret->setName(grp);
+ return ret;
+}
+
+DataArrayInt *MEDFileMesh::getNodeGroupsArr(const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ return getGroupsArr(1,grps,renum);
+}
+
+DataArrayInt *MEDFileMesh::getNodeFamilyArr(const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> tmp(1);
+ tmp[0]=fam;
+ DataArrayInt *ret=getNodeFamiliesArr(tmp,renum);
+ ret->setName(fam);
+ return ret;
+}
+
+DataArrayInt *MEDFileMesh::getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ return getFamiliesArr(1,fams,renum);
+}
+
+void MEDFileMesh::setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum) throw(INTERP_KERNEL::Exception)
+{
+ if(grps.empty())
+ return ;
+ std::set<std::string> grpsName;
+ std::vector<std::string> grpsName2(grps.size());
+ int i=0;
+
+ for(std::vector<const DataArrayInt *>::const_iterator it=grps.begin();it!=grps.end();it++,i++)
+ {
+ grpsName.insert((*it)->getName());
+ grpsName2[i]=(*it)->getName();
+ }
+ if(grpsName.size()!=grps.size())
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different each other !");
+ if(grpsName.find(std::string(""))!=grpsName.end())
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different empty string !");
+ int sz=getSizeAtLevel(meshDimRelToMaxExt);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam;
+ std::vector< std::vector<int> > fidsOfGroups;
+ if(!renum)
+ {
+ fam=DataArrayInt::MakePartition(grps,sz,fidsOfGroups);
+ }
+ else
+ {
+ std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > grps2(grps.size());
+ for(unsigned int i=0;i<grps.size();i++)
+ {
+ grps2[i]=MEDFileUMeshSplitL1::Renumber(getRevNumberFieldAtLevel(meshDimRelToMaxExt),grps[i]);
+ grps2[i]->setName(grps[i]->getName().c_str());
+ }
+ std::vector<const DataArrayInt *> grps3(grps2.begin(),grps2.end());
+ fam=DataArrayInt::MakePartition(grps3,sz,fidsOfGroups);
+ }
+ int offset=1;
+ if(!_families.empty())
+ offset=getMaxFamilyId()+1;
+ TranslateFamilyIds(offset,fam,fidsOfGroups);
+ std::set<int> ids=fam->getDifferentValues();
+ appendFamilyEntries(ids,fidsOfGroups,grpsName2);
+ setFamilyFieldArr(meshDimRelToMaxExt,fam);
+}
+
+/*!
+ * This method append into '_families' attribute the families whose ids are in 'famIds'. Warning 'famIds' are expected to be ids
+ * not in '_families'. Groups information are given in parameters in order to give to families representative names.
+ * For the moment, the two last input parameters are not taken into account.
+ */
+void MEDFileMesh::appendFamilyEntries(const std::set<int>& famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames)
+{
+ std::map<int,std::string> famInv;
+ for(std::set<int>::const_iterator it=famIds.begin();it!=famIds.end();it++)
+ {
+ std::ostringstream oss;
+ oss << "Family_" << (*it);
+ _families[oss.str()]=(*it);
+ famInv[*it]=oss.str();
+ }
+ int i=0;
+ for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGrps.begin();it1!=fidsOfGrps.end();it1++,i++)
+ {
+ for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
+ {
+ _groups[grpNames[i]].push_back(famInv[*it2]);
+ }
+ }
+}
+
+void MEDFileMesh::TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp)
+{
+ famArr->applyLin(1,offset,0);
+ for(std::vector< std::vector<int> >::iterator it1=famIdsPerGrp.begin();it1!=famIdsPerGrp.end();it1++)
+ std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus<int>(),offset));
+}
+
+MEDFileUMesh *MEDFileUMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
+{
+ MEDFileUtilities::CheckFileForRead(fileName);
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ return new MEDFileUMesh(fid,mName,dt,it);
+}
+
+MEDFileUMesh *MEDFileUMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> ms=MEDLoader::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,MED_ACC_RDONLY);
+ int dt,it;
+ ParaMEDMEM::MEDCouplingMeshType meshType;
+ std::string dummy2;
+ MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
+ return new MEDFileUMesh(fid,ms.front().c_str(),dt,it);
+}
+
+MEDFileUMesh *MEDFileUMesh::New()
+{
+ return new MEDFileUMesh;
+}
+
+bool MEDFileUMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
+{
+ if(!MEDFileMesh::isEqual(other,eps,what))
+ return false;
+ const MEDFileUMesh *otherC=dynamic_cast<const MEDFileUMesh *>(other);
+ if(!otherC)
+ {
+ what="Mesh types differ ! This is unstructured and other is NOT !";
+ return false;
+ }
+ clearNonDiscrAttributes();
+ otherC->clearNonDiscrAttributes();
+ const DataArrayDouble *coo1=_coords;
+ const DataArrayDouble *coo2=otherC->_coords;
+ if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
+ {
+ what="Mismatch of coordinates ! One is defined and not other !";
+ return false;
+ }
+ if(coo1)
+ {
+ bool ret=coo1->isEqual(*coo2,eps);
+ if(!ret)
+ {
+ what="Coords differ !";
+ return false;
+ }
+ }
+ const DataArrayInt *famc1=_fam_coords;
+ const DataArrayInt *famc2=otherC->_fam_coords;
+ if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
+ {
+ what="Mismatch of families arr on nodes ! One is defined and not other !";
+ return false;
+ }
+ if(famc1)
+ {
+ bool ret=famc1->isEqual(*famc2);
+ if(!ret)
+ {
+ what="Families arr on node differ !";
+ return false;
+ }
+ }
+ const DataArrayInt *numc1=_num_coords;
+ const DataArrayInt *numc2=otherC->_num_coords;
+ if((numc1==0 && numc2!=0) || (numc1!=0 && numc2==0))
+ {
+ what="Mismatch of numbering arr on nodes ! One is defined and not other !";
+ return false;
+ }
+ if(numc1)
+ {
+ bool ret=numc1->isEqual(*numc2);
+ if(!ret)
+ {
+ what="Numbering arr on node differ !";
+ return false;
+ }
+ }
+ if(_ms.size()!=otherC->_ms.size())
+ {
+ what="Number of levels differs !";
+ return false;
+ }
+ std::size_t sz=_ms.size();
+ for(std::size_t i=0;i<sz;i++)
+ {
+ const MEDFileUMeshSplitL1 *s1=_ms[i];
+ const MEDFileUMeshSplitL1 *s2=otherC->_ms[i];
+ if((s1==0 && s2!=0) || (s1!=0 && s2==0))
+ {
+ what="Mismatch of presence of sub levels !";
+ return false;
+ }
+ if(s1)
+ {
+ bool ret=s1->isEqual(s2,eps,what);
+ if(!ret)
+ return false;
+ }
+ }
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> > _ms;
+ return true;
+}
+
+void MEDFileUMesh::clearNonDiscrAttributes() const
+{
+ MEDFileMesh::clearNonDiscrAttributes();
+ const DataArrayDouble *coo1=_coords;
+ if(coo1)
+ ((DataArrayDouble *)coo1)->setName("");//This parameter is not discriminant for comparison
+ const DataArrayInt *famc1=_fam_coords;
+ if(famc1)
+ ((DataArrayInt *)famc1)->setName("");//This parameter is not discriminant for comparison
+ const DataArrayInt *numc1=_num_coords;
+ if(numc1)
+ ((DataArrayInt *)numc1)->setName("");//This parameter is not discriminant for comparison
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
+ {
+ const MEDFileUMeshSplitL1 *tmp=(*it);
+ if(tmp)
+ tmp->clearNonDiscrAttributes();
+ }
+}
+
+MEDFileUMesh::MEDFileUMesh()
+{
+}
+
+MEDFileUMesh::MEDFileUMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
+try
+ {
+ loadUMeshFromFile(fid,mName,dt,it);
+ }
+catch(INTERP_KERNEL::Exception& e)
+ {
+ throw e;
+ }
+
+void MEDFileUMesh::loadUMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
+{
+ MEDFileUMeshL2 loaderl2;
+ ParaMEDMEM::MEDCouplingMeshType meshType;
+ int dummy0,dummy1;
+ std::string dummy2;
+ int mid=MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2);
+ if(meshType!=UNSTRUCTURED)
+ {
+ std::ostringstream oss; oss << "Trying to load as unstructured an existing mesh with name '" << mName << "' !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ loaderl2.loadAll(fid,mid,mName,dt,it);
+ int lev=loaderl2.getNumberOfLevels();
+ _ms.resize(lev);
+ for(int i=0;i<lev;i++)
+ {
+ if(!loaderl2.emptyLev(i))
+ _ms[i]=new MEDFileUMeshSplitL1(loaderl2,mName,i);
+ else
+ _ms[i]=0;
+ }
+ MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups);
+ //
+ setName(loaderl2.getName());
+ setDescription(loaderl2.getDescription());
+ setIteration(loaderl2.getIteration());
+ setOrder(loaderl2.getOrder());
+ setTimeValue(loaderl2.getTime());
+ setTimeUnit(loaderl2.getTimeUnit());
+ _coords=loaderl2.getCoords();
+ _fam_coords=loaderl2.getCoordsFamily();
+ _num_coords=loaderl2.getCoordsNum();
+ computeRevNum();
+}
+
+MEDFileUMesh::~MEDFileUMesh()
+{
+}
+
+void MEDFileUMesh::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
+{
+ if(_name.empty())
+ throw INTERP_KERNEL::Exception("MEDFileUMesh : name is empty. MED file ask for a NON EMPTY name !");
+ if(!existsFamily(0))
+ (const_cast<MEDFileUMesh *>(this))->addFamily(DFT_FAM_NAME,0);
+ med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
+ std::ostringstream oss; oss << "MEDFileUMesh : error on attempt to write in file : \"" << fileName << "\"";
+ MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
+ const DataArrayDouble *coo=_coords;
+ INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
+ MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str);
+ MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str);
+ int spaceDim=coo?coo->getNumberOfComponents():0;
+ int mdim=getMeshDimension();
+ INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
+ for(int i=0;i<spaceDim;i++)
+ {
+ 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,MEDLoader::_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,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
+ }
+ MEDmeshCr(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
+ MEDFileUMeshL2::WriteCoords(fid,maa,_iteration,_order,_time,_coords,_fam_coords,_num_coords);
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
+ if((const MEDFileUMeshSplitL1 *)(*it)!=0)
+ (*it)->write(fid,maa,mdim);
+ MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str);
+}
+
+std::vector<int> MEDFileUMesh::getNonEmptyLevels() const
+{
+ std::vector<int> ret;
+ int lev=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--)
+ if((const MEDFileUMeshSplitL1 *)(*it)!=0)
+ if(!(*it)->empty())
+ ret.push_back(lev);
+ return ret;
+}
+
+std::vector<int> MEDFileUMesh::getNonEmptyLevelsExt() const
+{
+ std::vector<int> ret0=getNonEmptyLevels();
+ if((const DataArrayDouble *) _coords)
+ {
+ std::vector<int> ret(ret0.size()+1);
+ ret[0]=1;
+ std::copy(ret0.begin(),ret0.end(),ret.begin()+1);
return ret;
}
- std::vector<int> famIds=getFamiliesIds(fams);
+ return ret0;
+}
+
+int MEDFileUMesh::getMeshDimension() const
+{
+ int lev=0;
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev++)
+ if((const MEDFileUMeshSplitL1 *)(*it)!=0)
+ return (*it)->getMeshDimension()+lev;
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getMeshDimension : impossible to find a mesh dimension !");
+}
+
+int MEDFileUMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt==1)
+ {
+ if(!((const DataArrayDouble *)_coords))
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getSizeAtLevel : no coordinates specified !");
+ return _coords->getNumberOfTuples();
+ }
+ return getMeshAtLevSafe(meshDimRelToMaxExt)->getSize();
+}
+
+const DataArrayInt *MEDFileUMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt==1)
+ {
+ if(!((const DataArrayInt *)_fam_coords))
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamilyFieldAtLevel : no coordinates specified !");
+ return _fam_coords;
+ }
const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
- return l1->getFamilyPart(famIds,renum);
+ return l1->getFamilyField();
}
-DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
+const DataArrayInt *MEDFileUMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
{
- std::vector<int> famIds=getFamiliesIds(fams);
if(meshDimRelToMaxExt==1)
{
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam_coords->getIdsEqualList(famIds);
- return MEDFileUMeshSplitL1::Renumber(_num_coords,da);
+ if(!((const DataArrayInt *)_num_coords))
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getNumberFieldAtLevel : no coordinates renum specified !");
+ return _num_coords;
}
const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
- return l1->getFamilyPartArr(famIds,renum);
+ return l1->getNumberField();
+}
+
+const DataArrayInt *MEDFileUMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt==1)
+ {
+ if(!((const DataArrayInt *)_num_coords))
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getRevNumberFieldAtLevel : no coordinates renum specified !");
+ return _rev_num_coords;
+ }
+ const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
+ return l1->getRevNumberField();
}
-DataArrayInt *MEDFileUMesh::getNodeGroupArr(const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
+DataArrayDouble *MEDFileUMesh::getCoords() const
+{
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(_coords);
+ if((DataArrayDouble *)tmp)
+ {
+ tmp->incrRef();
+ return tmp;
+ }
+ return 0;
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
{
+ synchronizeTinyInfoOnLeaves();
std::vector<std::string> tmp(1);
tmp[0]=grp;
- DataArrayInt *ret=getNodeGroupsArr(tmp,renum);
+ MEDCouplingUMesh *ret=getGroups(meshDimRelToMaxExt,tmp,renum);
ret->setName(grp);
return ret;
}
-DataArrayInt *MEDFileUMesh::getNodeGroupsArr(const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
+MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
{
- return getGroupsArr(1,grps,renum);
+ synchronizeTinyInfoOnLeaves();
+ std::set<std::string> fams;
+ for(std::vector<std::string>::const_iterator it=grps.begin();it!=grps.end();it++)
+ {
+ std::map<std::string, std::vector<std::string> >::const_iterator it2=_groups.find(*it);
+ if(it2==_groups.end())
+ {
+ std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it;
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ fams.insert((*it2).second.begin(),(*it2).second.end());
+ }
+ std::vector<std::string> fams2(fams.begin(),fams.end());
+ return getFamilies(meshDimRelToMaxExt,fams2,renum);
}
-DataArrayInt *MEDFileUMesh::getNodeFamilyArr(const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
+MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
{
+ synchronizeTinyInfoOnLeaves();
std::vector<std::string> tmp(1);
tmp[0]=fam;
- DataArrayInt *ret=getNodeFamiliesArr(tmp,renum);
+ MEDCouplingUMesh *ret=getFamilies(meshDimRelToMaxExt,tmp,renum);
ret->setName(fam);
return ret;
}
-DataArrayInt *MEDFileUMesh::getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
+MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ synchronizeTinyInfoOnLeaves();
+ if(meshDimRelToMaxExt==1)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=getFamiliesArr(1,fams,renum);
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> c=_coords->selectByTupleId(arr->getConstPointer(),arr->getConstPointer()+arr->getNbOfElems());
+ ret->setCoords(c);
+ ret->incrRef();
+ return ret;
+ }
+ std::vector<int> famIds=getFamiliesIds(fams);
+ const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
+ return l1->getFamilyPart(famIds,renum);
+}
+
+DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
{
- return getFamiliesArr(1,fams,renum);
+ std::vector<int> famIds=getFamiliesIds(fams);
+ if(meshDimRelToMaxExt==1)
+ {
+ if((const DataArrayInt *)_fam_coords)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam_coords->getIdsEqualList(famIds);
+ if(renum)
+ return MEDFileUMeshSplitL1::Renumber(_num_coords,da);
+ else
+ {
+ da->incrRef();
+ return da;
+ }
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamiliesArr : no family array specified on nodes !");
+ }
+ const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
+ return l1->getFamilyPartArr(famIds,renum);
}
MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renum) const throw(INTERP_KERNEL::Exception)
{
+ synchronizeTinyInfoOnLeaves();
if(meshDimRelToMaxExt==1)
{
if(!renum)
MEDCouplingUMesh *umesh=MEDCouplingUMesh::New();
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> cc=_coords->deepCpy();
umesh->setCoords(cc);
+ MEDFileUMeshSplitL1::ClearNonDiscrAttributes(umesh);
return umesh;
}
}
return l1->getWholeMesh(renum);
}
+MEDCouplingMesh *MEDFileUMesh::getGenMeshAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception)
+{
+ return getMeshAtLevel(meshDimRelToMax,false);
+}
+
MEDCouplingUMesh *MEDFileUMesh::getLevel0Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
{
return getMeshAtLevel(0,renum);
return getMeshAtLevel(-3,renum);
}
-bool MEDFileUMesh::existsFamily(int famId) const
-{
- for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
- if((*it2).second==famId)
- return true;
- return false;
-}
-
-bool MEDFileUMesh::existsFamily(const char *familyName) const
-{
- std::string fname(familyName);
- return _families.find(fname)!=_families.end();
-}
-
const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
{
if(meshDimRelToMaxExt==1)
_fam_coords->fillWithZero();
}
-void MEDFileUMesh::setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum) throw(INTERP_KERNEL::Exception)
-{
- if(grps.empty())
- return ;
- std::set<std::string> grpsName;
- std::vector<std::string> grpsName2(grps.size());
- int i=0;
-
- for(std::vector<const DataArrayInt *>::const_iterator it=grps.begin();it!=grps.end();it++,i++)
- {
- grpsName.insert((*it)->getName());
- grpsName2[i]=(*it)->getName();
- }
- if(grpsName.size()!=grps.size())
- throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different each other !");
- if(grpsName.find(std::string(""))!=grpsName.end())
- throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different empty string !");
- int sz=getSizeAtLevel(meshDimRelToMaxExt);
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam;
- std::vector< std::vector<int> > fidsOfGroups;
- if(!renum)
- {
- fam=DataArrayInt::MakePartition(grps,sz,fidsOfGroups);
- }
- else
- {
- std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > grps2(grps.size());
- for(unsigned int i=0;i<grps.size();i++)
- {
- grps2[i]=MEDFileUMeshSplitL1::Renumber(getRevNumberFieldAtLevel(meshDimRelToMaxExt),grps[i]);
- grps2[i]->setName(grps[i]->getName().c_str());
- }
- std::vector<const DataArrayInt *> grps3(grps2.begin(),grps2.end());
- fam=DataArrayInt::MakePartition(grps3,sz,fidsOfGroups);
- }
- int offset=1;
- if(!_families.empty())
- offset=getMaxFamilyId()+1;
- TranslateFamilyIds(offset,fam,fidsOfGroups);
- std::set<int> ids=fam->getDifferentValues();
- appendFamilyEntries(ids,fidsOfGroups,grpsName2);
- setFamilyArr(meshDimRelToMaxExt,fam);
-}
-
void MEDFileUMesh::eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
{
if(meshDimRelToMaxExt==1)
}
-void MEDFileUMesh::copyFamGrpMapsFrom(const MEDFileUMesh& other)
-{
- _groups=other._groups;
- _families=other._families;
-}
-
-void MEDFileUMesh::setFamilyInfo(const std::map<std::string,int>& info)
-{
- _families=info;
-}
-
-void MEDFileUMesh::setGroupInfo(const std::map<std::string, std::vector<std::string> >&info)
-{
- _groups=info;
-}
-
void MEDFileUMesh::setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception)
{
std::string oldName=getFamilyNameGivenId(id);
return ret;
}
-void MEDFileUMesh::setFamilyArr(int meshDimRelToMaxExt, DataArrayInt *famArr)
+void MEDFileUMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception)
{
if(meshDimRelToMaxExt==1)
{
return ;
}
if(meshDimRelToMaxExt>1)
- throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyArr : Dimension request is invalid (>1) !");
+ throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyFieldArr : Dimension request is invalid (>1) !");
int traducedRk=-meshDimRelToMaxExt;
if(traducedRk>=(int)_ms.size())
throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
return _ms[traducedRk]->setFamilyArr(famArr);
}
-void MEDFileUMesh::setRenumArr(int meshDimRelToMaxExt, DataArrayInt *renumArr)
+void MEDFileUMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception)
{
if(meshDimRelToMaxExt==1)
{
return _ms[traducedRk]->setRenumArr(renumArr);
}
-void MEDFileUMesh::TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp)
+void MEDFileUMesh::synchronizeTinyInfoOnLeaves() const
{
- famArr->applyLin(1,offset,0);
- for(std::vector< std::vector<int> >::iterator it1=famIdsPerGrp.begin();it1!=famIdsPerGrp.end();it1++)
- std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus<int>(),offset));
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
+ if((const MEDFileUMeshSplitL1 *)(*it))
+ (*it)->synchronizeTinyInfo(*this);
}
-/*!
- * This method append into '_families' attribute the families whose ids are in 'famIds'. Warning 'famIds' are expected to be ids
- * not in '_families'. Groups information are given in parameters in order to give to families representative names.
- * For the moment, the two last input parameters are not taken into account.
- */
-void MEDFileUMesh::appendFamilyEntries(const std::set<int>& famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames)
+void MEDFileUMesh::computeRevNum() const
{
- std::map<int,std::string> famInv;
- for(std::set<int>::const_iterator it=famIds.begin();it!=famIds.end();it++)
+ if((const DataArrayInt *)_num_coords)
{
- std::ostringstream oss;
- oss << "Family_" << (*it);
- _families[oss.str()]=(*it);
- famInv[*it]=oss.str();
+ int pos;
+ int maxValue=_num_coords->getMaxValue(pos);
+ _rev_num_coords=_num_coords->invertArrayN2O2O2N(maxValue+1);
}
- int i=0;
- for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGrps.begin();it1!=fidsOfGrps.end();it1++,i++)
+}
+
+MEDFileCMesh *MEDFileCMesh::New()
+{
+ return new MEDFileCMesh;
+}
+
+MEDFileCMesh *MEDFileCMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
+ if(ms.empty())
{
- for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
+ 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,MED_ACC_RDONLY);
+ int dt,it;
+ ParaMEDMEM::MEDCouplingMeshType meshType;
+ std::string dummy2;
+ MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
+ return new MEDFileCMesh(fid,ms.front().c_str(),dt,it);
+}
+
+MEDFileCMesh *MEDFileCMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
+{
+ MEDFileUtilities::CheckFileForRead(fileName);
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ return new MEDFileCMesh(fid,mName,dt,it);
+}
+
+bool MEDFileCMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
+{
+ if(!MEDFileMesh::isEqual(other,eps,what))
+ return false;
+ const MEDFileCMesh *otherC=dynamic_cast<const MEDFileCMesh *>(other);
+ if(!otherC)
+ {
+ what="Mesh types differ ! This is cartesian and other is NOT !";
+ return false;
+ }
+ clearNonDiscrAttributes();
+ otherC->clearNonDiscrAttributes();
+ const MEDCouplingCMesh *coo1=_cmesh;
+ const MEDCouplingCMesh *coo2=otherC->_cmesh;
+ if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
+ {
+ what="Mismatch of cartesian meshes ! One is defined and not other !";
+ return false;
+ }
+ if(coo1)
+ {
+ bool ret=coo1->isEqual(coo2,eps);
+ if(!ret)
{
- _groups[grpNames[i]].push_back(famInv[*it2]);
+ what="cartesian meshes differ !";
+ return false;
+ }
+ }
+ const DataArrayInt *famc1=_fam_nodes;
+ const DataArrayInt *famc2=otherC->_fam_nodes;
+ if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
+ {
+ what="Mismatch of families arr on nodes ! One is defined and not other !";
+ return false;
+ }
+ if(famc1)
+ {
+ bool ret=famc1->isEqual(*famc2);
+ if(!ret)
+ {
+ what="Families arr on nodes differ !";
+ return false;
+ }
+ }
+ famc1=_fam_cells;
+ famc2=otherC->_fam_cells;
+ if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
+ {
+ what="Mismatch of families arr on cells ! One is defined and not other !";
+ return false;
+ }
+ if(famc1)
+ {
+ bool ret=famc1->isEqual(*famc2);
+ if(!ret)
+ {
+ what="Families arr on cells differ !";
+ return false;
+ }
+ }
+ famc1=_num_nodes;
+ famc2=otherC->_num_nodes;
+ if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
+ {
+ what="Mismatch of numbering arr on nodes ! One is defined and not other !";
+ return false;
+ }
+ if(famc1)
+ {
+ bool ret=famc1->isEqual(*famc2);
+ if(!ret)
+ {
+ what="Numbering arr on nodes differ !";
+ return false;
+ }
+ }
+ famc1=_num_cells;
+ famc2=otherC->_num_cells;
+ if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
+ {
+ what="Mismatch of numbering arr on cells ! One is defined and not other !";
+ return false;
+ }
+ if(famc1)
+ {
+ bool ret=famc1->isEqual(*famc2);
+ if(!ret)
+ {
+ what="Numbering arr on cells differ !";
+ return false;
}
}
+ return true;
}
-/*!
- * This method appends a new entry in _families attribute. An exception is thrown if either the famId is already
- * kept by an another familyName. An exception is thrown if name 'familyName' is alreadyset with a different 'famId'.
- */
-void MEDFileUMesh::addFamily(int famId, const char *familyName) throw(INTERP_KERNEL::Exception)
+void MEDFileCMesh::clearNonDiscrAttributes() const
{
- std::string fname(familyName);
- std::map<std::string,int>::const_iterator it=_families.find(fname);
- if(it==_families.end())
+ MEDFileMesh::clearNonDiscrAttributes();
+ MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_cmesh);
+ const DataArrayInt *tmp=_fam_nodes;
+ if(tmp)
+ (const_cast<DataArrayInt *>(tmp))->setName("");
+ tmp=_num_nodes;
+ if(tmp)
+ (const_cast<DataArrayInt *>(tmp))->setName("");
+ tmp=_fam_cells;
+ if(tmp)
+ (const_cast<DataArrayInt *>(tmp))->setName("");
+ tmp=_num_cells;
+ if(tmp)
+ (const_cast<DataArrayInt *>(tmp))->setName("");
+}
+
+MEDFileCMesh::MEDFileCMesh()
+{
+}
+
+MEDFileCMesh::MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
+try
+ {
+ loadCMeshFromFile(fid,mName,dt,it);
+ }
+catch(INTERP_KERNEL::Exception& e)
+ {
+ throw e;
+ }
+
+void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
+{
+ MEDFileCMeshL2 loaderl2;
+ ParaMEDMEM::MEDCouplingMeshType meshType;
+ int dummy0,dummy1;
+ std::string dtunit;
+ int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit);
+ if(meshType!=CARTESIAN)
{
- for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
- if((*it2).second==famId)
- {
- std::ostringstream oss;
- oss << "MEDFileUMesh::addFamily : Family \"" << (*it2).first << "\" already exists with specified id : " << famId << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- _families[fname]=famId;
+ std::ostringstream oss; oss << "Trying to load as cartesian an existing mesh with name '" << mName << "' that is NOT cartesian !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ loaderl2.loadAll(fid,mid,mName,dt,it);
+ MEDCouplingCMesh *mesh=loaderl2.getMesh();
+ mesh->incrRef();
+ _cmesh=mesh;
+ setName(loaderl2.getName());
+ setDescription(loaderl2.getDescription());
+ setIteration(loaderl2.getIteration());
+ setOrder(loaderl2.getOrder());
+ setTimeValue(loaderl2.getTime());
+ setTimeUnit(loaderl2.getTimeUnit());
+ MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups);
+ med_bool chgt=MED_FALSE,trsf=MED_FALSE;
+ int nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf);
+ if(nbOfElt>0)
+ {
+ _fam_nodes=DataArrayInt::New();
+ _fam_nodes->alloc(nbOfElt,1);
+ MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_fam_nodes->getPointer());
+ }
+ nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_NUMBER,MED_NODAL,&chgt,&trsf);
+ if(nbOfElt>0)
+ {
+ _num_nodes=DataArrayInt::New();
+ _num_nodes->alloc(nbOfElt,1);
+ MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_num_nodes->getPointer());
+ }
+ int spaceDim=mesh->getSpaceDimension();
+ med_geometry_type geoTypeReq=MED_NONE;
+ switch(spaceDim)
+ {
+ case 3:
+ geoTypeReq=MED_HEXA8;
+ break;
+ case 2:
+ geoTypeReq=MED_QUAD4;
+ break;
+ case 1:
+ geoTypeReq=MED_SEG2;
+ break;
+ case 0:
+ geoTypeReq=MED_POINT1;
+ break;
+ default:
+ throw INTERP_KERNEL::Exception("Invalid spacedim detected for cartesian mesh ! Must be in (1,2,3) !");
+ }
+ nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf);
+ if(nbOfElt>0)
+ {
+ _fam_cells=DataArrayInt::New();
+ _fam_cells->alloc(nbOfElt,1);
+ MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_fam_cells->getPointer());
+ }
+ nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_NUMBER,MED_NODAL,&chgt,&trsf);
+ if(nbOfElt>0)
+ {
+ _num_cells=DataArrayInt::New();
+ _num_cells->alloc(nbOfElt,1);
+ MEDmeshEntityNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_num_cells->getPointer());
+ }
+}
+
+const MEDCouplingCMesh *MEDFileCMesh::getMesh() const
+{
+ synchronizeTinyInfoOnLeaves();
+ return _cmesh;
+}
+
+MEDCouplingMesh *MEDFileCMesh::getGenMeshAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMax!=0)
+ throw INTERP_KERNEL::Exception("MEDFileCMesh does not support multi level for mesh 0 expected as input !");
+ const MEDCouplingCMesh *m=getMesh();
+ if(m)
+ m->incrRef();
+ return const_cast<MEDCouplingCMesh *>(m);
+}
+
+void MEDFileCMesh::setMesh(MEDCouplingCMesh *m)
+{
+ if(m)
+ m->incrRef();
+ _cmesh=m;
+}
+
+void MEDFileCMesh::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
+{
+ if(_name.empty())
+ throw INTERP_KERNEL::Exception("MEDFileCMesh : name is empty. MED file ask for a NON EMPTY name !");
+ if(!existsFamily(0))
+ (const_cast<MEDFileCMesh *>(this))->addFamily(DFT_FAM_NAME,0);
+ med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
+ MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
+ std::ostringstream oss; oss << "MEDFileCMesh : error on attempt to write in file : \"" << fileName << "\"";
+ MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
+ INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str);
+ MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str);
+ MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_LNAME_SIZE,dtunit,_too_long_str);
+ int spaceDim=_cmesh->getSpaceDimension();
+ INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
+ for(int i=0;i<spaceDim;i++)
+ {
+ std::string info(_cmesh->getCoordsAt(i)->getInfoOnComponent(0));
+ std::string c,u;
+ MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
+ MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,MEDLoader::_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,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
+ }
+ MEDmeshCr(fid,maa,spaceDim,spaceDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
+ MEDmeshGridTypeWr(fid,maa,MED_CARTESIAN_GRID);
+ for(int i=0;i<spaceDim;i++)
+ {
+ DataArrayDouble *da=_cmesh->getCoordsAt(i);
+ MEDmeshGridIndexCoordinateWr(fid,maa,_iteration,_order,_time,i+1,da->getNumberOfTuples(),da->getConstPointer());
}
+ if((const DataArrayInt *)_fam_cells)
+ MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_CELL,MED_GEO_ALL,_fam_cells->getNumberOfTuples(),_fam_cells->getConstPointer());
+ if((const DataArrayInt *)_fam_nodes)
+ MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_NODE,MED_NONE,_fam_nodes->getNumberOfTuples(),_fam_nodes->getConstPointer());
+ //
+ MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str);
+}
+
+int MEDFileCMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getSizeAtLevel : Only available for levels 0 or 1 !");
+ if(!((const MEDCouplingCMesh *)_cmesh))
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getSizeAtLevel : No cartesian mesh set !");
+ if(meshDimRelToMaxExt==0)
+ return _cmesh->getNumberOfCells();
else
+ return _cmesh->getNumberOfNodes();
+}
+
+void MEDFileCMesh::synchronizeTinyInfoOnLeaves() const
+{
+ const MEDCouplingCMesh *cmesh=_cmesh;
+ (const_cast<MEDCouplingCMesh *>(cmesh))->setName(_name.c_str());
+ (const_cast<MEDCouplingCMesh *>(cmesh))->setDescription(_desc_name.c_str());
+ (const_cast<MEDCouplingCMesh *>(cmesh))->setTime(_time,_iteration,_order);
+ (const_cast<MEDCouplingCMesh *>(cmesh))->setTimeUnit(_dt_unit.c_str());
+}
+
+DataArrayInt *MEDFileCMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : Only available for levels 0 or 1 !");
+ std::vector<int> famIds=getFamiliesIds(fams);
+ if(meshDimRelToMaxExt==1)
{
- if((*it).second!=famId)
+ if((const DataArrayInt *)_fam_nodes)
{
- std::ostringstream oss;
- oss << "MEDFileUMesh::addFamily : Family \"" << fname << "\" already exists but has id set to " << (*it).second << " different from asked famId " << famId << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam_nodes->getIdsEqualList(famIds);
+ if(renum)
+ return MEDFileUMeshSplitL1::Renumber(_num_nodes,da);
+ else
+ {
+ da->incrRef();
+ return da;
+ }
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : no family array specified on nodes !");
+ }
+ else
+ {
+ if((const DataArrayInt *)_fam_cells)
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam_cells->getIdsEqualList(famIds);
+ if(renum)
+ return MEDFileUMeshSplitL1::Renumber(_num_cells,da);
+ else
+ {
+ da->incrRef();
+ return da;
+ }
}
+ else
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : no family array specified on cells !");
}
}
-void MEDFileUMesh::computeRevNum() const
+void MEDFileCMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception)
{
- if((const DataArrayInt *)_num_coords)
+ if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::setRenumFieldArr : Only available for levels 0 or 1 !");
+ if(famArr)
+ famArr->incrRef();
+ if(meshDimRelToMaxExt==0)
+ _fam_cells=famArr;
+ else
+ _fam_nodes=famArr;
+}
+
+void MEDFileCMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::setRenumFieldArr : Only available for levels 0 or 1 !");
+ if(renumArr)
+ renumArr->incrRef();
+ if(meshDimRelToMaxExt==0)
+ _num_cells=renumArr;
+ else
+ _num_nodes=renumArr;
+}
+
+const DataArrayInt *MEDFileCMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamilyFieldAtLevel : Only available for levels 0 or 1 !");
+ if(meshDimRelToMaxExt==0)
+ return _fam_cells;
+ else
+ return _fam_nodes;
+}
+
+const DataArrayInt *MEDFileCMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getNumberFieldAtLevel : Only available for levels 0 or 1 !");
+ if(meshDimRelToMaxExt==0)
+ return _num_cells;
+ else
+ return _num_nodes;
+}
+
+const DataArrayInt *MEDFileCMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+{
+ if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : Only available for levels 0 or 1 !");
+ if(meshDimRelToMaxExt==0)
{
- int pos;
- int maxValue=_num_coords->getMaxValue(pos);
- _rev_num_coords=_num_coords->invertArrayN2O2O2N(maxValue+1);
+ if((const DataArrayInt *)_num_cells)
+ {
+ int pos;
+ int maxValue=_num_cells->getMaxValue(pos);
+ _rev_num_cells=_num_cells->invertArrayN2O2O2N(maxValue+1);
+ return _rev_num_cells;
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no cell renumbering for a request on reverse numbering !");
+ }
+ else
+ {
+ if((const DataArrayInt *)_num_nodes)
+ {
+ int pos;
+ int maxValue=_num_nodes->getMaxValue(pos);
+ _rev_num_nodes=_num_nodes->invertArrayN2O2O2N(maxValue+1);
+ return _rev_num_nodes;
+ }
+ else
+ throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no node renumbering for a request on reverse numbering !");
}
}
class MEDFileMesh : public RefCountObject
{
public:
- static MEDFileMesh *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
+ static MEDFileMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ static MEDFileMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception);
+ virtual bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const;
+ virtual void clearNonDiscrAttributes() const;
void setName(const char *name) { _name=name; }
const char *getName() const { return _name.c_str(); }
void setUnivName(const char *name) { _univ_name=name; }
const char *getUnivName() const { return _univ_name.c_str(); }
void setDescription(const char *name) { _desc_name=name; }
const char *getDescription() const { return _desc_name.c_str(); }
+ void setOrder(int order) { _order=order; }
+ int getOrder() const { return _order; }
+ void setIteration(int it) { _iteration=it; }
+ int getIteration() const { return _iteration; }
+ void setTimeValue(double time) { _time=time; }
+ void setTime(double time, int dt, int it) { _time=time; _iteration=dt; _order=it; }
+ double getTime(int& dt, int& it) { dt=_iteration; it=_order; return _time; }
+ double getTimeValue() const { return _time; }
+ void setTimeUnit(const char *unit) { _dt_unit=unit; }
+ const char *getTimeUnit() const { return _dt_unit.c_str(); }
+ virtual void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) = 0;
+ virtual int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
+ virtual MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) = 0;
+ //
+ bool areFamsEqual(const MEDFileMesh *other, std::string& what) const;
+ bool areGrpsEqual(const MEDFileMesh *other, std::string& what) const;
+ bool existsFamily(int famId) const;
+ bool existsFamily(const char *familyName) const;
+ void setFamilyId(const char *familyName, int id);
+ void addFamily(const char *familyName, int id) throw(INTERP_KERNEL::Exception);
+ void addGrpOnFamily(const char *grpName, const char *famName) throw(INTERP_KERNEL::Exception);
+ void setFamilyInfo(const std::map<std::string,int>& info);
+ void setGroupInfo(const std::map<std::string, std::vector<std::string> >&info);
+ void copyFamGrpMapsFrom(const MEDFileMesh& other);
+ const std::map<std::string,int>& getFamilyInfo() const { return _families; }
+ const std::map<std::string, std::vector<std::string> >& getGroupInfo() const { return _groups; }
+ std::vector<std::string> getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception);
+ std::vector<std::string> getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception);
+ std::vector<std::string> getGroupsNames() const;
+ std::vector<std::string> getFamiliesNames() const;
+ void removeGroup(const char *name) throw(INTERP_KERNEL::Exception);
+ void removeFamily(const char *name) throw(INTERP_KERNEL::Exception);
+ void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception);
+ void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception);
+ int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception);
+ int getMaxFamilyId() const throw(INTERP_KERNEL::Exception);
+ std::vector<int> getFamiliesIds(const std::vector<std::string>& famNames) const throw(INTERP_KERNEL::Exception);
+ std::string getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception);
+ //
+ virtual void setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum=false) throw(INTERP_KERNEL::Exception);
+ virtual void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception) = 0;
+ virtual void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception) = 0;
+ virtual const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
+ virtual const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
+ virtual const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0;
+ virtual DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception) = 0;
+ virtual DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getNodeGroupArr(const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getNodeGroupsArr(const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
protected:
+ MEDFileMesh();
+ virtual void synchronizeTinyInfoOnLeaves() const = 0;
+ virtual void appendFamilyEntries(const std::set<int>& famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames);
+ static void TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp);
+ protected:
+ int _order;
+ int _iteration;
+ double _time;
+ std::string _dt_unit;
std::string _name;
std::string _univ_name;
std::string _desc_name;
+ protected:
+ std::map<std::string, std::vector<std::string> > _groups;
+ std::map<std::string,int> _families;
+ protected://policies on write
+ int _too_long_str;
+ int _zipconn_pol;
+ public:
+ static const char DFT_FAM_NAME[];
};
class MEDFileUMesh : public MEDFileMesh
{
+ friend class MEDFileMesh;
public:
- static MEDFileUMesh *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
+ static MEDFileUMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception);
static MEDFileUMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
static MEDFileUMesh *New();
+ bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const;
+ void clearNonDiscrAttributes() const;
~MEDFileUMesh();
//
- void removeGroup(const char *name) throw(INTERP_KERNEL::Exception);
- void removeFamily(const char *name) throw(INTERP_KERNEL::Exception);
- void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception);
- void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception);
- //
void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
- int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception);
- int getMaxFamilyId() const throw(INTERP_KERNEL::Exception);
- std::vector<int> getFamiliesIds(const std::vector<std::string>& famNames) const throw(INTERP_KERNEL::Exception);
- std::string getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception);
int getMeshDimension() const;
int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
- std::vector<std::string> getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception);
- std::vector<std::string> getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception);
- std::vector<std::string> getGroupsNames() const;
- std::vector<std::string> getFamiliesNames() const;
std::vector<int> getNonEmptyLevels() const;
std::vector<int> getNonEmptyLevelsExt() const;
DataArrayDouble *getCoords() const;
MEDCouplingUMesh *getGroup(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
MEDCouplingUMesh *getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
MEDCouplingUMesh *getFamily(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
MEDCouplingUMesh *getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *getNodeGroupArr(const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *getNodeGroupsArr(const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
- DataArrayInt *getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
MEDCouplingUMesh *getMeshAtLevel(int meshDimRelToMaxExt, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception);
MEDCouplingUMesh *getLevel0Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
MEDCouplingUMesh *getLevelM1Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
MEDCouplingUMesh *getLevelM2Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
MEDCouplingUMesh *getLevelM3Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
- const std::map<std::string,int>& getFamilyInfo() const { return _families; }
- const std::map<std::string, std::vector<std::string> >& getGroupInfo() const { return _groups; }
- bool existsFamily(int famId) const;
- bool existsFamily(const char *familyName) const;
//
- void copyFamGrpMapsFrom(const MEDFileUMesh& other);
- void setFamilyInfo(const std::map<std::string,int>& info);
- void setGroupInfo(const std::map<std::string, std::vector<std::string> >&info);
void setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception);
void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
- void setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum=false) throw(INTERP_KERNEL::Exception);
void eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception);
void setFamilyField(DataArrayInt *arr, const std::vector< std::vector< int > > &userfids, const std::vector<std::string>& grpNames, bool renum=false) throw(INTERP_KERNEL::Exception);
- void setFamilyArr(int meshDimRelToMaxExt, DataArrayInt *famArr);
- void setRenumArr(int meshDimRelToMaxExt, DataArrayInt *renumArr);
+ void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception);
+ void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception);
void addNodeGroup(const std::string& name, const std::vector<int>& ids) throw(INTERP_KERNEL::Exception);
void setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception);
void setMeshAtLevelOld(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception);
void setGroupsFromScratch(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception);
void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum) throw(INTERP_KERNEL::Exception);
void optimizeFamilies() throw(INTERP_KERNEL::Exception);
- void addFamily(int famId, const char *familyName) throw(INTERP_KERNEL::Exception);
private:
MEDFileUMesh();
- MEDFileUMesh(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception);
+ MEDFileUMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
+ void loadUMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
const MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
MEDFileUMeshSplitL1 *getMeshAtLevSafe(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception);
void checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception);
DataArrayDouble *checkMultiMesh(const std::vector<const MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception);
- void appendFamilyEntries(const std::set<int>& famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames);
void computeRevNum() const;
- static void TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp);
+ void synchronizeTinyInfoOnLeaves() const;
private:
- std::map<std::string, std::vector<std::string> > _groups;
- std::map<std::string,int> _families;
std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> > _ms;
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _coords;
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_coords;
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_coords;
- int _too_long_str;
- int _zipconn_pol;
};
class MEDFileCMesh : public MEDFileMesh
{
+ friend class MEDFileMesh;
+ public:
+ static MEDFileCMesh *New();
+ static MEDFileCMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ static MEDFileCMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception);
+ bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const;
+ void clearNonDiscrAttributes() const;
+ const MEDCouplingCMesh *getMesh() const;
+ MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception);
+ void setMesh(MEDCouplingCMesh *m);
+ void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
+ int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception);
+ void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception);
+ const DataArrayInt *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
+ const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
+ const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
+ private:
+ MEDFileCMesh();
+ void synchronizeTinyInfoOnLeaves() const;
+ MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
+ void loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
+ private:
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_nodes;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_nodes;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam_cells;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_cells;
+ mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_nodes;
+ mutable MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _rev_num_cells;
};
}
#include "InterpKernelAutoPtr.hxx"
#include "CellModel.hxx"
-extern med_geometrie_element typmai3[32];
+extern med_geometry_type typmai3[32];
using namespace ParaMEDMEM;
-MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType geoElt2)
+MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType geoElt2)
{
- med_entite_maillage whichEntity;
- if(!isExisting(fid,mName,geoElt,whichEntity))
+ med_entity_type whichEntity;
+ if(!isExisting(fid,mName,dt,it,geoElt,whichEntity))
return 0;
- return new MEDFileUMeshPerType(fid,mName,mdim,geoElt,geoElt2,whichEntity);
+ return new MEDFileUMeshPerType(fid,mName,dt,it,mdim,geoElt,geoElt2,whichEntity);
}
-bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, med_geometrie_element geoElt, med_entite_maillage& whichEntity)
+bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, int dt, int it, med_geometry_type geoElt, med_entity_type& whichEntity)
{
- static const med_entite_maillage entities[3]={MED_MAILLE,MED_FACE,MED_ARETE};
+ static const med_entity_type entities[1]={MED_CELL};
int nbOfElt=0;
- for(int i=0;i<3;i++)
+ for(int i=0;i<1;i++)
{
- int tmp=MEDnEntMaa(fid,(char *)mName,MED_CONN,entities[i],geoElt,MED_NOD);
+ med_bool changement,transformation;
+ int tmp=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoElt,MED_CONNECTIVITY,MED_NODAL,
+ &changement,&transformation);
if(tmp>nbOfElt)
{
nbOfElt=tmp;
return cm.getDimension();
}
-MEDFileUMeshPerType::MEDFileUMeshPerType(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type,
- med_entite_maillage entity):_type(type),_entity(entity)
+MEDFileUMeshPerType::MEDFileUMeshPerType(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
+ med_entity_type entity):_type(type),_entity(entity)
{
- int curNbOfElem=MEDnEntMaa(fid,(char *)mName,MED_CONN,entity,geoElt,MED_NOD);
+ med_bool changement,transformation;
+ int curNbOfElem=MEDmeshnEntity(fid,mName,dt,it,entity,geoElt,MED_CONNECTIVITY,MED_NODAL,
+ &changement,&transformation);
if(type!=INTERP_KERNEL::NORM_POLYGON && type!=INTERP_KERNEL::NORM_POLYHED)
{
- loadFromStaticType(fid,mName,mdim,curNbOfElem,geoElt,type,entity);
+ loadFromStaticType(fid,mName,dt,it,mdim,curNbOfElem,geoElt,type,entity);
return;
}
if(type==INTERP_KERNEL::NORM_POLYGON)
{
- loadPolyg(fid,mName,mdim,curNbOfElem,geoElt,entity);
+ loadPolyg(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity);
return;
}
//if(type==INTERP_KERNEL::NORM_POLYHED)
- loadPolyh(fid,mName,mdim,curNbOfElem,geoElt,entity);
+ loadPolyh(fid,mName,dt,it,mdim,curNbOfElem,geoElt,entity);
}
-void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type,
- med_entite_maillage entity)
+void MEDFileUMeshPerType::loadFromStaticType(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
+ med_entity_type entity)
{
_conn=DataArrayInt::New();
int nbOfNodesPerCell=(geoElt%100);
_conn->alloc((nbOfNodesPerCell+1)*curNbOfElem,1);
_conn_index=DataArrayInt::New();
_conn_index->alloc(curNbOfElem+1,1);
- int *connTab=new int[(nbOfNodesPerCell)*curNbOfElem];
+ INTERP_KERNEL::AutoPtr<int> connTab=new int[(nbOfNodesPerCell)*curNbOfElem];
_num=DataArrayInt::New();
_num->alloc(curNbOfElem,1);
- char *noms=new char[MED_TAILLE_PNOM*curNbOfElem+1];
- med_booleen inoele, inuele;
_fam=DataArrayInt::New();
_fam->alloc(curNbOfElem,1);
- MEDelementsLire(fid,(char *)mName,mdim,connTab,MED_FULL_INTERLACE,noms,&inoele,_num->getPointer(),&inuele,_fam->getPointer(),curNbOfElem,entity,geoElt,MED_NOD);
- delete [] noms;
+ med_bool withname=MED_FALSE,withnumber=MED_FALSE,withfam=MED_FALSE;
+ INTERP_KERNEL::AutoPtr<char> noms=new char[MED_SNAME_SIZE*curNbOfElem+1];
+ MEDmeshElementRd(fid,mName,dt,it,entity,geoElt,MED_NODAL,MED_FULL_INTERLACE,connTab,&withname,noms,&withnumber,_num->getPointer(),&withfam,_fam->getPointer());
int *w1=_conn->getPointer();
int *w2=_conn_index->getPointer();
*w2++=0;
w1=std::transform(wi,wi+nbOfNodesPerCell,w1,std::bind2nd(std::plus<int>(),-1));
*w2=w2[-1]+nbOfNodesPerCell+1;
}
- delete [] connTab;
- if(!inuele)
+ if(!withnumber)
_num=0;
}
-void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt,
- med_entite_maillage entity)
+void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int dt, int it, int mdim, int arraySize, med_geometry_type geoElt,
+ med_entity_type entity)
{
- med_int arraySize;
- MEDpolygoneInfo(fid,(char *)mName,entity,MED_NOD,&arraySize);
+ med_bool changement,transformation;
+ med_int curNbOfElem=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1;
_conn_index=DataArrayInt::New();
_conn_index->alloc(curNbOfElem+1,1);
_conn=DataArrayInt::New();
_num->alloc(curNbOfElem,1);
_fam=DataArrayInt::New();
_fam->alloc(curNbOfElem,1);
- int *locConn=new int[arraySize];
- MEDpolygoneConnLire(fid,(char *)mName,_conn_index->getPointer(),curNbOfElem+1,locConn,entity,MED_NOD);
+ INTERP_KERNEL::AutoPtr<int> locConn=new int[arraySize];
+ MEDmeshPolygonRd(fid,mName,dt,it,MED_CELL,MED_NODAL,_conn_index->getPointer(),locConn);
int *w1=_conn->getPointer();
int *w2=_conn_index->getPointer();
const int *wi=locConn;
*w2=*w2-1+i;
}
*w2=*w2-1+curNbOfElem;
- delete [] locConn;
- MEDfamLire(fid,(char *)mName,_fam->getPointer(),curNbOfElem,entity,MED_POLYGONE);
- if(MEDnumLire(fid,(char *)mName,_num->getPointer(),curNbOfElem,entity,MED_POLYGONE)!=0)
+ if(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYGON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
+ {
+ if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,MED_POLYGON,_fam->getPointer())!=0)
+ std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0);
+ }
+ else
+ std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0);
+ if(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYGON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
+ {
+ if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,MED_POLYGON,_num->getPointer())!=0)
+ _num=0;
+ }
+ else
_num=0;
}
-void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt,
- med_entite_maillage entity)
+void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, int connFaceLgth, med_geometry_type geoElt,
+ med_entity_type entity)
{
- med_int indexFaceLgth,connFaceLgth;
- MEDpolyedreInfo(fid,(char*)mName,MED_NOD,&indexFaceLgth,&connFaceLgth);
- int *index=new int[curNbOfElem+1];
- int *indexFace=new int[indexFaceLgth];
- int *locConn=new int[connFaceLgth];
+ med_bool changement,transformation;
+ med_int indexFaceLgth=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation);
+ int curNbOfElem=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1;
+ INTERP_KERNEL::AutoPtr<int> index=new int[curNbOfElem+1];
+ INTERP_KERNEL::AutoPtr<int> indexFace=new int[indexFaceLgth];
+ INTERP_KERNEL::AutoPtr<int> locConn=new int[connFaceLgth];
_fam=DataArrayInt::New();
_fam->alloc(curNbOfElem,1);
- MEDpolyedreConnLire(fid,(char *)mName,index,curNbOfElem+1,indexFace,indexFaceLgth,locConn,MED_NOD);
- MEDfamLire(fid,(char *)mName,_fam->getPointer(),curNbOfElem,MED_MAILLE,MED_POLYEDRE);
+ MEDmeshPolyhedronRd(fid,mName,dt,it,MED_CELL,MED_NODAL,index,indexFace,locConn);
+ if(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
+ {
+ if(MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,_fam->getPointer())!=0)
+ std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0);
+ }
+ else
+ std::fill(_fam->getPointer(),_fam->getPointer()+curNbOfElem,0);
int arraySize=connFaceLgth;
for(int i=0;i<curNbOfElem;i++)
arraySize+=index[i+1]-index[i]-1;
wFinalConn=std::transform(locConn+indexFace[j]-1,locConn+indexFace[j+1]-1,wFinalConn,std::bind2nd(std::plus<int>(),-1));
}
}
- delete [] index;
- delete [] locConn;
- delete [] indexFace;
_num=DataArrayInt::New();
_num->alloc(curNbOfElem,1);
- if(MEDnumLire(fid,(char *)mName,_num->getPointer(),curNbOfElem,MED_MAILLE,MED_POLYEDRE)!=0)
+ if(MEDmeshnEntity(fid,mName,dt,it,MED_CELL,MED_POLYHEDRON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
+ {
+ if(MEDmeshEntityNumberRd(fid,mName,dt,it,entity,MED_POLYHEDRON,_num->getPointer())!=0)
+ _num=0;
+ }
+ else
_num=0;
}
int nbOfCells=m->getNumberOfCells();
if(nbOfCells<1)
return ;
+ int dt,it;
+ double timm=m->getTime(dt,it);
INTERP_KERNEL::NormalizedCellType ikt=m->getTypeOfCell(0);
const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(ikt);
- med_geometrie_element curMedType=typmai3[(int)ikt];
+ med_geometry_type curMedType=typmai3[(int)ikt];
const int *conn=m->getNodalConnectivity()->getConstPointer();
const int *connI=m->getNodalConnectivityIndex()->getConstPointer();
if(ikt!=INTERP_KERNEL::NORM_POLYGON && ikt!=INTERP_KERNEL::NORM_POLYHED)
int *w=tab;
for(int i=0;i<nbOfCells;i++)
w=std::transform(conn+connI[i]+1,conn+connI[i+1],w,std::bind2nd(std::plus<int>(),1));
- MEDconnEcr(fid,(char *)mname,mdim,tab,MED_FULL_INTERLACE,nbOfCells,MED_MAILLE,curMedType,MED_NOD);
+ MEDmeshElementConnectivityWr(fid,mname,dt,it,timm,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,nbOfCells,tab);
}
else
{
wI[1]=wI[0]+connI[i+1]-connI[i]-1;
w=std::transform(conn+connI[i]+1,conn+connI[i+1],w,std::bind2nd(std::plus<int>(),1));
}
- MEDpolygoneConnEcr(fid,(char *)mname,tab1,nbOfCells,tab2,MED_MAILLE,MED_NOD);
+ MEDmeshPolygonWr(fid,mname,dt,it,timm,MED_CELL,MED_NODAL,nbOfCells+1,tab1,tab2);
}
else
{
}
w1[1]=w1[0]+nbOfFaces;
}
- MEDpolyedreConnEcr(fid,(char *)mname,tab1,nbOfCells+1,tab2,nbOfFaces+1,
- bigtab,MED_NOD);
+ MEDmeshPolyhedronWr(fid,mname,dt,it,timm,MED_CELL,MED_NODAL,nbOfCells+1,tab1,nbOfFaces+1,tab2,bigtab);
}
}
if(fam)
- MEDfamEcr(fid,(char *)mname,(int *)fam->getConstPointer(),nbOfCells,MED_MAILLE,curMedType);
+ MEDmeshEntityFamilyNumberWr(fid,mname,dt,it,MED_CELL,curMedType,nbOfCells,fam->getConstPointer());
if(num)
- MEDnumEcr(fid,(char *)mname,(int *)num->getConstPointer(),nbOfCells,MED_MAILLE,curMedType);
+ MEDmeshEntityNumberWr(fid,mname,dt,it,MED_CELL,curMedType,nbOfCells,num->getConstPointer());
}
class MEDFileUMeshPerType : public RefCountObject
{
public:
- static MEDFileUMeshPerType *New(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType geoElt2);
- static bool isExisting(med_idt fid, const char *mName, med_geometrie_element geoElt, med_entite_maillage& whichEntity);
+ static MEDFileUMeshPerType *New(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType geoElt2);
+ static bool isExisting(med_idt fid, const char *mName, int dt, int it, med_geometry_type geoElt, med_entity_type& whichEntity);
int getDim() const;
const DataArrayInt *getNodal() const { return _conn; }
const DataArrayInt *getNodalIndex() const { return _conn_index; }
const DataArrayInt *getNum() const { return _num; }
static void write(med_idt fid, const char *mname, int mdim, const MEDCouplingUMesh *m, const DataArrayInt *fam, const DataArrayInt *num);
private:
- MEDFileUMeshPerType(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type,
- med_entite_maillage entity);
- void loadFromStaticType(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type,
- med_entite_maillage entity);
- void loadPolyg(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt,
- med_entite_maillage entity);
- void loadPolyh(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt,
- med_entite_maillage entity);
+ MEDFileUMeshPerType(med_idt fid, const char *mName, int dt, int it, int mdim, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
+ med_entity_type entity);
+ void loadFromStaticType(med_idt fid, const char *mName, int dt, int it, int mdim, int curNbOfElem, med_geometry_type geoElt, INTERP_KERNEL::NormalizedCellType type,
+ med_entity_type entity);
+ void loadPolyg(med_idt fid, const char *mName, int dt, int it, int mdim, int arraySize, med_geometry_type geoElt,
+ med_entity_type entity);
+ void loadPolyh(med_idt fid, const char *mName, int dt, int it, int mdim, int connFaceLgth, med_geometry_type geoElt,
+ med_entity_type entity);
private:
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _conn;
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _conn_index;
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
INTERP_KERNEL::NormalizedCellType _type;
- med_entite_maillage _entity;
+ med_entity_type _entity;
};
}
//
#include "MEDFileMeshLL.hxx"
+#include "MEDFileMesh.hxx"
#include "MEDLoaderBase.hxx"
#include "MEDCouplingUMesh.hxx"
#include <set>
-extern med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2];
-extern INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2];
-extern med_geometrie_element typmainoeud[1];
+extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
+extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
+extern med_geometry_type typmainoeud[1];
using namespace ParaMEDMEM;
-MEDFileMeshL2::MEDFileMeshL2():_name(MED_TAILLE_NOM),_description(MED_TAILLE_DESC)
+MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_dt_unit(MED_LNAME_SIZE)
{
}
-MEDFileUMeshL2::MEDFileUMeshL2()
-{
-}
-
-void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const char *mName)
-{
- _name.set(mName);
- med_maillage type_maillage;
- med_int Mdim;
- if(MEDmaaInfo(fid,mId,(char *)mName,&Mdim,&type_maillage,_description.getPointer())!=0)
- throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !");
- if(type_maillage!=MED_NON_STRUCTURE)
- throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !");
- loadConnectivity(fid,Mdim,mName);
- loadCoords(fid,mId,Mdim,mName);
-}
-
-void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const char *mName)
-{
- _per_type_mesh.resize(1);
- _per_type_mesh[0].clear();
- for(int j=0;j<MED_NBR_GEOMETRIE_MAILLE+2;j++)
- {
- MEDFileUMeshPerType *tmp=MEDFileUMeshPerType::New(fid,mName,mdim,typmai[j],typmai2[j]);
- if(tmp)
- _per_type_mesh[0].push_back(tmp);
- }
- sortTypes();
-}
-
-void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, int mdim, const char *mName) throw(INTERP_KERNEL::Exception)
-{
- med_int edim=MEDdimEspaceLire(fid,(char *)mName);
- int spaceDim=std::max((int)mdim,(int)edim);
- int nCoords=MEDnEntMaa(fid,(char *)mName,MED_COOR,MED_NOEUD,(med_geometrie_element)0,(med_connectivite)0);
- _coords=DataArrayDouble::New();
- _coords->alloc(nCoords,spaceDim);
- double *coordsPtr=_coords->getPointer();
- med_repere repere;
- char *comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
- char *unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
- MEDcoordLire(fid,(char *)mName,spaceDim,coordsPtr,MED_FULL_INTERLACE,MED_ALL,NULL,0,&repere,comp,unit);
- _fam_coords=DataArrayInt::New();
- _fam_coords->alloc(nCoords,1);
- _num_coords=DataArrayInt::New();
- _num_coords->alloc(nCoords,1);
- MEDfamLire(fid,(char *)mName,_fam_coords->getPointer(),nCoords,MED_NOEUD,MED_NONE);
- if(MEDnumLire(fid,(char *)mName,_num_coords->getPointer(),nCoords,MED_NOEUD,MED_NONE)!=0)
- _num_coords=0;
- for(int i=0;i<spaceDim;i++)
- {
- std::string n,u;
- std::string info=MEDLoaderBase::buildUnionUnit(comp+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM,unit+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
- _coords->setInfoOnComponent(i,info.c_str());
- }
- delete [] comp;
- delete [] unit;
-}
-
-void MEDFileUMeshL2::sortTypes()
+int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const char *mname, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception)
{
- std::set<int> mdims;
- std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
- _per_type_mesh.clear();
- for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
- mdims.insert((*it)->getDim());
- if(mdims.empty())
- return;
- int mdim=*mdims.rbegin();
- _per_type_mesh.resize(mdim+1);
- for(int dim=mdim+1;dim!=0;dim--)
- {
- std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
- for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
- if((*it)->getDim()==dim-1)
- elt.push_back(*it);
- }
-}
-
-int MEDFileUMeshL2::getMeshIdFromName(med_idt fid, const char *mname) throw(INTERP_KERNEL::Exception)
-{
- med_maillage type_maillage;
- char maillage_description[MED_TAILLE_DESC+1];
- med_int dim;
- char nommaa[MED_TAILLE_NOM+1];
- med_int n=MEDnMaa(fid);
+ med_mesh_type type_maillage;
+ char maillage_description[MED_COMMENT_SIZE+1];
+ char dtunit[MED_LNAME_SIZE+1];
+ med_int spaceDim,dim;
+ char nommaa[MED_NAME_SIZE+1];
+ med_int n=MEDnMesh(fid);
bool found=false;
int ret=-1;
+ med_sorting_type stype;
std::vector<std::string> ms;
- for(int i=0;i<n;i++)
+ int nstep;
+ med_axis_type axistype;
+ for(int i=0;i<n && !found;i++)
{
- MEDmaaInfo(fid,i+1,nommaa,&dim,&type_maillage,maillage_description);
+ int naxis=MEDmeshnAxis(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
+ MEDmeshInfo(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit);
+ dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit));
std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
ms.push_back(cur);
if(cur==mname)
std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss,", "));
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
+ switch(type_maillage)
+ {
+ case MED_UNSTRUCTURED_MESH:
+ meshType=UNSTRUCTURED;
+ break;
+ case MED_STRUCTURED_MESH:
+ meshType=CARTESIAN;
+ break;
+ default:
+ throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !");
+ }
+ med_int numdt,numit;
+ med_float dtt;
+ MEDmeshComputationStepInfo(fid,mname,1,&numdt,&numit,&dtt);
+ dt=numdt; it=numit;
return ret;
}
-void MEDFileUMeshL2::readFamiliesAndGrps(med_idt fid, const char *meshName, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps)
+double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const char *mName, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception)
{
- char nomfam[MED_TAILLE_NOM+1];
+ bool found=false;
+ med_int numdt,numit;
+ med_float dtt;
+ std::vector< std::pair<int,int> > p(nstep);
+ for(int i=0;i<nstep;i++)
+ {
+ MEDmeshComputationStepInfo(fid,mName,i+1,&numdt,&numit,&dtt);
+ p[i]=std::make_pair<int,int>(numdt,numit);
+ found=(numdt==dt) && (numit==numit);
+ }
+ if(!found)
+ {
+ std::ostringstream oss; oss << "No such iteration=" << dt << ",order=" << it << " numbers found for mesh '" << mName << "' ! ";
+ oss << "Possibilities are : ";
+ for(int i=0;i<nstep;i++)
+ oss << "(" << p[i].first << "," << p[i].second << "), ";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ return dtt;
+}
+
+std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception)
+{
+ med_mesh_type type_maillage;
+ med_int spaceDim;
+ med_sorting_type stype;
+ med_axis_type axistype;
+ int naxis=MEDmeshnAxis(fid,mId);
+ INTERP_KERNEL::AutoPtr<char> nameTmp=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
+ if(MEDmeshInfo(fid,mId,nameTmp,&spaceDim,&Mdim,&type_maillage,_description.getPointer(),_dt_unit.getPointer(),
+ &stype,&nstep,&axistype,axisname,axisunit)!=0)
+ throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !");
+ switch(type_maillage)
+ {
+ case MED_UNSTRUCTURED_MESH:
+ meshType=UNSTRUCTURED;
+ break;
+ case MED_STRUCTURED_MESH:
+ meshType=CARTESIAN;
+ break;
+ default:
+ throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !");
+ }
+ //
+ std::vector<std::string> infosOnComp(naxis);
+ for(int i=0;i<naxis;i++)
+ {
+ std::string info=MEDLoaderBase::buildUnionUnit(((char *)axisname)+i*MED_SNAME_SIZE,MED_SNAME_SIZE,((char *)axisunit)+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
+ infosOnComp[i]=info;
+ }
+ return infosOnComp;
+}
+
+void MEDFileMeshL2::ReadFamiliesAndGrps(med_idt fid, const char *meshName, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps)
+{
+ char nomfam[MED_NAME_SIZE+1];
med_int numfam;
- int nfam=MEDnFam(fid,(char *)meshName);
+ int nfam=MEDnFamily(fid,meshName);
for(int i=0;i<nfam;i++)
{
- int ngro=MEDnGroupe(fid,(char *)meshName,i+1);
- med_int natt=MEDnAttribut(fid,(char *)meshName,i+1);
- med_int *attide=new int[natt];
- med_int *attval=new int[natt];
- char *attdes=new char[MED_TAILLE_DESC*natt+1];
- char *gro=new char[MED_TAILLE_LNOM*ngro+1];
- MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro);
- std::string famName=MEDLoaderBase::buildStringFromFortran(nomfam,MED_TAILLE_LNOM);
+ int ngro=MEDnFamilyGroup(fid,meshName,i+1);
+ med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
+ INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
+ INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
+ MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
+ std::string famName=MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE);
fams[famName]=numfam;
for(int j=0;j<ngro;j++)
{
- std::string groupname=MEDLoaderBase::buildStringFromFortran(gro+j*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
+ std::string groupname=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
grps[groupname].push_back(famName);
}
- delete [] attdes;
- delete [] gro;
- delete [] attide;
- delete [] attval;
}
}
-void MEDFileUMeshL2::writeFamiliesAndGrps(med_idt fid, const char *mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol)
+void MEDFileMeshL2::WriteFamiliesAndGrps(med_idt fid, const char *mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol)
{
for(std::map<std::string,int>::const_iterator it=fams.begin();it!=fams.end();it++)
{
grpsOfFam.push_back((*it1).first);
}
int ngro=grpsOfFam.size();
- INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_TAILLE_LNOM*ngro);
+ INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
int i=0;
for(std::vector<std::string>::const_iterator it2=grpsOfFam.begin();it2!=grpsOfFam.end();it2++,i++)
- MEDLoaderBase::safeStrCpy((*it2).c_str(),MED_TAILLE_LNOM-1,groName+i*MED_TAILLE_LNOM,tooLongStrPol);
- INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_TAILLE_NOM,famName,tooLongStrPol);
- MEDfamCr(fid,(char *)mname,famName,(*it).second,0,0,0,0,groName,ngro);
+ MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,tooLongStrPol);
+ INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_NAME_SIZE,famName,tooLongStrPol);
+ int ret=MEDfamilyCr(fid,mname,famName,(*it).second,ngro,groName);
+ ret++;
}
}
-void MEDFileUMeshL2::writeCoords(med_idt fid, const char *mname, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords)
+MEDFileUMeshL2::MEDFileUMeshL2()
{
- if(!coords)
- return ;
- int spaceDim=coords->getNumberOfComponents();
- INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
- INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
+}
+
+void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const char *mName, int dt, int it)
+{
+ _name.set(mName);
+ int nstep;
+ int Mdim;
+ ParaMEDMEM::MEDCouplingMeshType meshType;
+ std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim);
+ if(meshType!=UNSTRUCTURED)
+ throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !");
+ _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
+ _iteration=dt;
+ _order=it;
+ loadConnectivity(fid,Mdim,mName,dt,it);//to improve check (dt,it) coherency
+ loadCoords(fid,mId,infosOnComp,mName,dt,it);
+}
+
+void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it)
+{
+ _per_type_mesh.resize(1);
+ _per_type_mesh[0].clear();
+ for(int j=0;j<MED_N_CELL_FIXED_GEO;j++)
+ {
+ MEDFileUMeshPerType *tmp=MEDFileUMeshPerType::New(fid,mName,dt,it,mdim,typmai[j],typmai2[j]);
+ if(tmp)
+ _per_type_mesh[0].push_back(tmp);
+ }
+ sortTypes();
+}
+
+void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
+{
+ int spaceDim=infosOnComp.size();
+ med_bool changement,transformation;
+ int nCoords=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
+ _coords=DataArrayDouble::New();
+ _coords->alloc(nCoords,spaceDim);
+ double *coordsPtr=_coords->getPointer();
+ MEDmeshNodeCoordinateRd(fid,mName,dt,it,MED_FULL_INTERLACE,coordsPtr);
+ _fam_coords=DataArrayInt::New();
+ _fam_coords->alloc(nCoords,1);
+ _num_coords=DataArrayInt::New();
+ _num_coords->alloc(nCoords,1);
+ if(MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
+ MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer());
+ else
+ _fam_coords=0;
+ if(MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
+ MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer());
+ else
+ _num_coords=0;
for(int i=0;i<spaceDim;i++)
+ _coords->setInfoOnComponent(i,infosOnComp[i].c_str());
+}
+
+void MEDFileUMeshL2::sortTypes()
+{
+ std::set<int> mdims;
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
+ _per_type_mesh.clear();
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
+ mdims.insert((*it)->getDim());
+ if(mdims.empty())
+ return;
+ int mdim=*mdims.rbegin();
+ _per_type_mesh.resize(mdim+1);
+ for(int dim=mdim+1;dim!=0;dim--)
{
- std::string info=coords->getInfoOnComponent(i);
- std::string c,u;
- MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
- MEDLoaderBase::safeStrCpy(c.c_str(),MED_TAILLE_PNOM-1,comp+i*MED_TAILLE_PNOM,0);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
- MEDLoaderBase::safeStrCpy(u.c_str(),MED_TAILLE_PNOM-1,unit+i*MED_TAILLE_PNOM,0);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
+ std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
+ if((*it)->getDim()==dim-1)
+ elt.push_back(*it);
}
- MEDcoordEcr(fid,(char *)mname,spaceDim,coords->getPointer(),MED_FULL_INTERLACE,coords->getNumberOfTuples(),MED_CART,comp,unit);
- MEDfamEcr(fid,(char *)mname,famCoords->getPointer(),famCoords->getNumberOfTuples(),MED_NOEUD,MED_NONE);
+}
+
+void MEDFileUMeshL2::WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords)
+{
+ if(!coords)
+ return ;
+ MEDmeshNodeCoordinateWr(fid,mname,dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->getPointer());
+ if(famCoords)
+ MEDmeshEntityFamilyNumberWr(fid,mname,dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->getPointer());
if(numCoords)
- MEDnumEcr(fid,(char *)mname,numCoords->getPointer(),numCoords->getNumberOfTuples(),MED_NOEUD,MED_NONE);
+ MEDmeshEntityNumberWr(fid,mname,dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->getPointer());
}
bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
return true;
}
+MEDFileCMeshL2::MEDFileCMeshL2()
+{
+}
+
+void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
+{
+ _name.set(mName);
+ int nstep;
+ int Mdim;
+ ParaMEDMEM::MEDCouplingMeshType meshType;
+ std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim);
+ if(meshType!=CARTESIAN)
+ throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
+ _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
+ _iteration=dt;
+ _order=it;
+ //
+ med_grid_type gridtype;
+ MEDmeshGridTypeRd(fid,mName,&gridtype);
+ if(gridtype!=MED_CARTESIAN_GRID)
+ throw INTERP_KERNEL::Exception("Invalid cartesion mesh type ! Only Cartesian Grid supported ! Curvilinear grid will come soon !");
+ _cmesh=MEDCouplingCMesh::New();
+ for(int i=0;i<Mdim;i++)
+ {
+ med_data_type dataTypeReq=GetDataTypeCorrespondingToSpaceId(i);
+ med_bool chgt=MED_FALSE,trsf=MED_FALSE;
+ int nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,dataTypeReq,MED_NO_CMODE,&chgt,&trsf);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=DataArrayDouble::New();
+ da->alloc(nbOfElt,1);
+ da->setInfoOnComponent(0,infosOnComp[i].c_str());
+ MEDmeshGridIndexCoordinateRd(fid,mName,dt,it,i+1,da->getPointer());
+ _cmesh->setCoordsAt(i,da);
+ }
+}
+
+med_data_type MEDFileCMeshL2::GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception)
+{
+ switch(id)
+ {
+ case 0:
+ return MED_COORDINATE_AXIS1;
+ case 1:
+ return MED_COORDINATE_AXIS2;
+ case 2:
+ return MED_COORDINATE_AXIS3;
+ default:
+ throw INTERP_KERNEL::Exception("Invalid meshdim detected in Cartesian Grid !");
+ }
+}
+
MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0)
{
}
assignMesh(m,newOrOld);
}
+bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const
+{
+ const MEDCouplingUMesh *m1=_m_by_types;
+ const MEDCouplingUMesh *m2=other->_m_by_types;
+ if((m1==0 && m2!=0) || (m1!=0 && m2==0))
+ {
+ what="Presence of mesh in one sublevel and not in other!";
+ return false;
+ }
+ if(m1)
+ if(!m1->isEqual(m2,eps))
+ {
+ what="meshes at a sublevel are not deeply equal !";
+ return false;
+ }
+ const DataArrayInt *d1=_fam;
+ const DataArrayInt *d2=other->_fam;
+ if((d1==0 && d2!=0) || (d1!=0 && d2==0))
+ {
+ what="Presence of family arr in one sublevel and not in other!";
+ return false;
+ }
+ if(d1)
+ if(!d1->isEqual(*d2))
+ {
+ what="family arr at a sublevel are not deeply equal !";
+ return false;
+ }
+ d1=_num;
+ d2=other->_num;
+ if((d1==0 && d2!=0) || (d1!=0 && d2==0))
+ {
+ what="Presence of cell numbering arr in one sublevel and not in other!";
+ return false;
+ }
+ if(d1)
+ if(!d1->isEqual(*d2))
+ {
+ what="Numbering cell arr at a sublevel are not deeply equal !";
+ return false;
+ }
+ return true;
+}
+
+void MEDFileUMeshSplitL1::synchronizeTinyInfo(const MEDFileMesh& master) const
+{
+ const MEDCouplingUMesh *tmp=_m_by_types;
+ if(!tmp)
+ return ;
+ (const_cast<MEDCouplingUMesh *>(tmp))->setName(master.getName());
+ (const_cast<MEDCouplingUMesh *>(tmp))->setDescription(master.getDescription());
+ (const_cast<MEDCouplingUMesh *>(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
+ (const_cast<MEDCouplingUMesh *>(tmp))->setTimeUnit(master.getTimeUnit());
+}
+
+void MEDFileUMeshSplitL1::clearNonDiscrAttributes() const
+{
+ ClearNonDiscrAttributes(_m_by_types);
+}
+
+void MEDFileUMeshSplitL1::ClearNonDiscrAttributes(const MEDCouplingMesh *tmp)
+{
+ if(!tmp)
+ return ;
+ (const_cast<MEDCouplingMesh *>(tmp))->setName("");
+ (const_cast<MEDCouplingMesh *>(tmp))->setDescription("");
+ (const_cast<MEDCouplingMesh *>(tmp))->setTime(0.,-1,-1);
+ (const_cast<MEDCouplingMesh *>(tmp))->setTimeUnit("");
+}
+
void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception)
{
if(newOrOld)
m->incrRef();
_m=m;
_m_by_types=(MEDCouplingUMesh *)m->deepCpy();
- MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_m_by_types->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_m_by_types->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
if(!da->isIdentity())
{
_num=da->invertArrayO2N2N2O(m->getNumberOfCells());
}
else
{
- if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2))
+ if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh : the mode of mesh setting expects to follow the MED file numbering convention ! it is not the case !");
m->incrRef();
_m_by_types=m;
int nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells();
std::map<int,std::string> newfams;
std::map<int,int> famIdTrad;
- traduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams);
+ TraduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams);
for(int i=0;i<sz;i++)
corr[i]->decrRef();
int *w=_fam->getPointer();
return Renumber(_num,da);
}
-std::vector<int> MEDFileUMeshSplitL1::getNewFamiliesNumber(int nb, const std::map<std::string,int>& families)
+std::vector<int> MEDFileUMeshSplitL1::GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families)
{
int id=-1;
for(std::map<std::string,int>::const_iterator it=families.begin();it!=families.end();it++)
return ret;
}
-void MEDFileUMeshSplitL1::traduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
+void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams)
{
std::set<int> allfids;
#include "MEDFileBasis.hxx"
#include "MEDFileMeshElt.hxx"
+#include "MEDCouplingUMesh.hxx"
+#include "MEDCouplingCMesh.hxx"
#include "MEDCouplingAutoRefCountObjectPtr.hxx"
extern "C"
namespace ParaMEDMEM
{
- class MEDCouplingUMesh;
-
class MEDFileMeshL2 : public RefCountObject
{
public:
MEDFileMeshL2();
const char *getName() const { return _name.getReprForWrite(); }
- const char *getDescription() const { return _description.getReprForWrite(); }
+ const char *getDescription() const { return _description.getReprForWrite(); }
+ const char *getTimeUnit() const { return _dt_unit.getReprForWrite(); }
+ int getIteration() const { return _iteration; }
+ int getOrder() const { return _order; }
+ double getTime() { return _time; }
+ std::vector<std::string> getAxisInfoOnMesh(med_idt fid, int mId, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim) throw(INTERP_KERNEL::Exception);
+ static int GetMeshIdFromName(med_idt fid, const char *mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1) throw(INTERP_KERNEL::Exception);
+ static double CheckMeshTimeStep(med_idt fid, const char *mname, int nstep, int dt, int it) throw(INTERP_KERNEL::Exception);
+ static void ReadFamiliesAndGrps(med_idt fid, const char *mname, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps);
+ static void WriteFamiliesAndGrps(med_idt fid, const char *mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol);
protected:
MEDFileString _name;
MEDFileString _description;
+ MEDFileString _dt_unit;
+ int _iteration;
+ int _order;
+ double _time;
};
class MEDFileUMeshL2 : public MEDFileMeshL2
{
public:
MEDFileUMeshL2();
- void loadAll(med_idt fid, int mId, const char *mName);
- void loadConnectivity(med_idt fid, int mdim, const char *mName);
- void loadCoords(med_idt fid, int mId, int mdim, const char *mName) throw(INTERP_KERNEL::Exception);
+ void loadAll(med_idt fid, int mId, const char *mName, int dt, int it);
+ void loadConnectivity(med_idt fid, int mdim, const char *mName, int dt, int it);
+ void loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
int getNumberOfLevels() const { return _per_type_mesh.size(); }
bool emptyLev(int levId) const { return _per_type_mesh[levId].empty(); }
const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& getLev(int levId) const { return _per_type_mesh[levId]; }
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> getCoords() const { return _coords; }
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsFamily() const { return _fam_coords; }
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> getCoordsNum() const { return _num_coords; }
- static int getMeshIdFromName(med_idt fid, const char *mname) throw(INTERP_KERNEL::Exception);
- static void readFamiliesAndGrps(med_idt fid, const char *mname, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps);
- static void writeFamiliesAndGrps(med_idt fid, const char *mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol);
- static void writeCoords(med_idt fid, const char *mname, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords);
+ static void WriteCoords(med_idt fid, const char *mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords);
private:
void sortTypes();
private:
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num_coords;
};
- class MEDFileUMeshL2CMesh : public MEDFileMeshL2
+ class MEDFileCMeshL2 : public MEDFileMeshL2
{
+ public:
+ MEDFileCMeshL2();
+ void loadAll(med_idt fid, int mId, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception);
+ MEDCouplingCMesh *getMesh() { return _cmesh; }
+ private:
+ static med_data_type GetDataTypeCorrespondingToSpaceId(int id) throw(INTERP_KERNEL::Exception);
+ private:
+ MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> _cmesh;
};
+ class MEDFileMesh;
class MEDFileUMeshSplitL1;
class MEDFileUMeshPermCompute
MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const char *mName, int id);
MEDFileUMeshSplitL1(MEDCouplingUMesh *m);
MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld);
+ bool isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const;
+ void clearNonDiscrAttributes() const;
+ void synchronizeTinyInfo(const MEDFileMesh& master) const;
void assignMesh(MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
bool empty() const;
int getMeshDimension() const;
void setFamilyArr(DataArrayInt *famArr);
void setRenumArr(DataArrayInt *renumArr);
//
- static std::vector<int> getNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
- static void traduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
+ static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp);
+ static std::vector<int> GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families);
+ static void TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams);
static DataArrayInt *Renumber(const DataArrayInt *renum, const DataArrayInt *da);
static MEDCouplingUMesh *Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds);
#include <sstream>
-med_mode_acces MEDFileUtilities::TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception)
+med_access_mode MEDFileUtilities::TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception)
{
switch(medloaderwritemode)
{
case 2:
- return MED_CREATION;
+ return MED_ACC_CREAT;
case 1:
- return MED_LECTURE_AJOUT;
+ return MED_ACC_RDEXT;
case 0:
- return MED_LECTURE_ECRITURE;
+ return MED_ACC_RDWR;
default:
throw INTERP_KERNEL::Exception("Invalid write mode specified ! must be 0(write with no question), 1(append) or 2(creation)");
}
{
std::ostringstream oss;
oss << "MEDFile has returned an error code (" << code <<") : " << msg;
- MEDfermer(fid);
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
}
- int fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
if(fid<0)
{
oss << " has been detected as unreadable by MED file : impossible to read anything !";
}
oss << " has been detected readable but ";
int major,minor,release;
- MEDversionLire(fid,&major,&minor,&release);
+ MEDfileNumVersionRd(fid,&major,&minor,&release);
if(major<2 || (major==2 && minor<2))
{
oss << "version of MED file is < 2.2 : impossible to read anything !";
- MEDfermer(fid);
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- MEDfermer(fid);
+}
+
+MEDFileUtilities::AutoFid::AutoFid(med_idt fid):_fid(fid)
+{
+}
+
+MEDFileUtilities::AutoFid::operator med_idt() const
+{
+ return _fid;
+}
+
+MEDFileUtilities::AutoFid::~AutoFid()
+{
+ MEDfileClose(_fid);
}
namespace MEDFileUtilities
{
- med_mode_acces TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception);
+ med_access_mode TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception);
void CheckMEDCode(int code, med_idt fid, const char *msg) throw(INTERP_KERNEL::Exception);
void CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception);
+
+ class AutoFid
+ {
+ public:
+ AutoFid(med_idt fid);
+ operator med_idt() const;
+ ~AutoFid();
+ private:
+ med_idt _fid;
+ };
}
#endif
}
#include <string>
+#include <limits>
#include <cstring>
#include <sstream>
#include <fstream>
+#include <numeric>
#include <iterator>
#include <algorithm>
-#include <numeric>
-#include <limits>
-med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE+2] = { MED_POINT1,
- MED_SEG2,
- MED_SEG3,
- MED_TRIA3,
- MED_QUAD4,
- MED_TRIA6,
- MED_QUAD8,
- MED_TETRA4,
- MED_PYRA5,
- MED_PENTA6,
- MED_HEXA8,
- MED_TETRA10,
- MED_PYRA13,
- MED_PENTA15,
- MED_HEXA20,
- MED_POLYGONE,
- MED_POLYEDRE };
-
-med_geometrie_element typmainoeud[1] = { MED_NONE };
-
-INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2] = { INTERP_KERNEL::NORM_POINT1,
- INTERP_KERNEL::NORM_SEG2,
- INTERP_KERNEL::NORM_SEG3,
- INTERP_KERNEL::NORM_TRI3,
- INTERP_KERNEL::NORM_QUAD4,
- INTERP_KERNEL::NORM_TRI6,
- INTERP_KERNEL::NORM_QUAD8,
- INTERP_KERNEL::NORM_TETRA4,
- INTERP_KERNEL::NORM_PYRA5,
- INTERP_KERNEL::NORM_PENTA6,
- INTERP_KERNEL::NORM_HEXA8,
- INTERP_KERNEL::NORM_TETRA10,
- INTERP_KERNEL::NORM_PYRA13,
- INTERP_KERNEL::NORM_PENTA15,
- INTERP_KERNEL::NORM_HEXA20,
- INTERP_KERNEL::NORM_POLYGON,
- INTERP_KERNEL::NORM_POLYHED };
-
-med_geometrie_element typmai3[32] = { MED_POINT1,//0
- MED_SEG2,//1
- MED_SEG3,//2
- MED_TRIA3,//3
- MED_QUAD4,//4
- MED_POLYGONE,//5
- MED_TRIA6,//6
- MED_NONE,//7
- MED_QUAD8,//8
- MED_NONE,//9
- MED_NONE,//10
- MED_NONE,//11
- MED_NONE,//12
- MED_NONE,//13
- MED_TETRA4,//14
- MED_PYRA5,//15
- MED_PENTA6,//16
- MED_NONE,//17
- MED_HEXA8,//18
- MED_NONE,//19
- MED_TETRA10,//20
- MED_NONE,//21
- MED_NONE,//22
- MED_PYRA13,//23
- MED_NONE,//24
- MED_PENTA15,//25
- MED_NONE,//26
- MED_NONE,//27
- MED_NONE,//28
- MED_NONE,//29
- MED_HEXA20,//30
- MED_POLYEDRE//31
+med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
+ MED_SEG2,
+ MED_SEG3,
+ MED_SEG4,
+ MED_TRIA3,
+ MED_QUAD4,
+ MED_TRIA6,
+ MED_TRIA7,
+ MED_QUAD8,
+ MED_QUAD9,
+ MED_TETRA4,
+ MED_PYRA5,
+ MED_PENTA6,
+ MED_HEXA8,
+ MED_OCTA12,
+ MED_TETRA10,
+ MED_PYRA13,
+ MED_PENTA15,
+ MED_HEXA20,
+ MED_HEXA27,
+ MED_POLYGON,
+ MED_POLYHEDRON };
+
+med_geometry_type typmainoeud[1] = { MED_NONE };
+
+INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
+ INTERP_KERNEL::NORM_SEG2,
+ INTERP_KERNEL::NORM_SEG3,
+ INTERP_KERNEL::NORM_ERROR,//SEG4
+ INTERP_KERNEL::NORM_TRI3,
+ INTERP_KERNEL::NORM_QUAD4,
+ INTERP_KERNEL::NORM_TRI6,
+ INTERP_KERNEL::NORM_ERROR,//TRI7
+ INTERP_KERNEL::NORM_QUAD8,
+ INTERP_KERNEL::NORM_ERROR,//QUAD9
+ INTERP_KERNEL::NORM_TETRA4,
+ INTERP_KERNEL::NORM_PYRA5,
+ INTERP_KERNEL::NORM_PENTA6,
+ INTERP_KERNEL::NORM_HEXA8,
+ INTERP_KERNEL::NORM_HEXGP12,
+ INTERP_KERNEL::NORM_TETRA10,
+ INTERP_KERNEL::NORM_PYRA13,
+ INTERP_KERNEL::NORM_PENTA15,
+ INTERP_KERNEL::NORM_HEXA20,
+ INTERP_KERNEL::NORM_ERROR,//HEXA27
+ INTERP_KERNEL::NORM_POLYGON,
+ INTERP_KERNEL::NORM_POLYHED };
+
+med_geometry_type typmai3[32] = { MED_POINT1,//0
+ MED_SEG2,//1
+ MED_SEG3,//2
+ MED_TRIA3,//3
+ MED_QUAD4,//4
+ MED_POLYGON,//5
+ MED_TRIA6,//6
+ MED_NONE,//7
+ MED_QUAD8,//8
+ MED_NONE,//9
+ MED_NONE,//10
+ MED_NONE,//11
+ MED_NONE,//12
+ MED_NONE,//13
+ MED_TETRA4,//14
+ MED_PYRA5,//15
+ MED_PENTA6,//16
+ MED_NONE,//17
+ MED_HEXA8,//18
+ MED_NONE,//19
+ MED_TETRA10,//20
+ MED_NONE,//21
+ MED_OCTA12,//22
+ MED_PYRA13,//23
+ MED_NONE,//24
+ MED_PENTA15,//25
+ MED_NONE,//26
+ MED_NONE,//27
+ MED_NONE,//28
+ MED_NONE,//29
+ MED_HEXA20,//30
+ MED_POLYHEDRON//31
};
double MEDLoader::_EPS_FOR_NODE_COMP=1.e-12;
std::vector<int> getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector<std::string>& fams);
std::vector<int> getIdsFromGroups(const char *fileName, const char *meshName, const std::vector<std::string>& grps);
med_int getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception);
- void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entite_maillage& whichEntity);
+ void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity);
int readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector<int>& possibilities);
- void readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn);
+ void readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn, std::string& desc);
int buildMEDSubConnectivityOfOneType(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families, INTERP_KERNEL::NormalizedCellType type,
std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
{
- med_maillage type_maillage;
- char maillage_description[MED_TAILLE_DESC+1];
- med_int dim;
- char nommaa[MED_TAILLE_NOM+1];
- med_int n=MEDnMaa(fid);
+ med_mesh_type type_maillage;
+ char maillage_description[MED_COMMENT_SIZE+1];
+ char dtunit[MED_COMMENT_SIZE+1];
+ med_int space_dim;
+ med_int mesh_dim;
+ char nommaa[MED_NAME_SIZE+1];
+ med_axis_type axistype;
+ med_sorting_type stype;
+ med_int n=MEDnMesh(fid);
std::vector<std::string> ret(n);
for(int i=0;i<n;i++)
{
- MEDmaaInfo(fid,i+1,nommaa,&dim,&type_maillage,maillage_description);
+ int naxis=MEDmeshnAxis(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
+ int nstep;
+ MEDmeshInfo(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit);
std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
ret[i]=cur;
}
void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list<MEDLoader::MEDFieldDoublePerCellType>& data, MEDCouplingFieldDouble *f)
{
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- char locName[MED_TAILLE_NOM+1];
- int nloc=MEDnGauss(fid);
- med_geometrie_element typeGeo;
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ char locName[MED_NAME_SIZE+1];
+ int nloc=MEDnLocalization(fid);
+ med_geometry_type typeGeo;
for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=data.begin();iter!=data.end();iter++)
{
const std::string& loc=(*iter).getLocName();
int idLoc=1;
int nbOfGaussPt=-1;
+ med_int spaceDim;
for(;idLoc<=nloc;idLoc++)
{
- MEDgaussInfo(fid,idLoc,locName,&typeGeo,&nbOfGaussPt);
+ char geointerpname[MED_NAME_SIZE+1]="";
+ char ipointstructmeshname[MED_NAME_SIZE+1]="";
+ med_int nsectionmeshcell;
+ med_geometry_type sectiongeotype;
+ MEDlocalizationInfo(fid,idLoc,locName,&typeGeo,&spaceDim,&nbOfGaussPt, geointerpname, ipointstructmeshname, &nsectionmeshcell,
+ §iongeotype);
if(loc==locName)
break;
}
int dim=(int)INTERP_KERNEL::CellModel::getCellModel((*iter).getType()).getDimension();
int nbPtPerCell=(int)INTERP_KERNEL::CellModel::getCellModel((*iter).getType()).getNumberOfNodes();
std::vector<double> refcoo(nbPtPerCell*dim),gscoo(nbOfGaussPt*dim),w(nbOfGaussPt);
- MEDgaussLire(fid,(med_float *)&refcoo[0],(med_float *)&gscoo[0],(med_float *)&w[0],MED_FULL_INTERLACE,(char *)(*iter).getLocName().c_str());
+ MEDlocalizationRd(fid,(*iter).getLocName().c_str(),MED_FULL_INTERLACE,&refcoo[0],&gscoo[0],&w[0]);
f->setGaussLocalizationOnType((*iter).getType(),refcoo,gscoo,w);
}
- MEDfermer(fid);
+ MEDfileClose(fid);
}
void MEDLoader::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception)
std::vector<std::string> MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception)
{
CheckFileForRead(fileName);
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
std::vector<std::string> ret=MEDLoaderNS::getMeshNamesFid(fid);
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
{
CheckFileForRead(fileName);
std::vector<std::string> ret;
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nbFields=MEDnChamp(fid,0);
//
- med_type_champ typcha;
- //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
- med_int ngauss=0;
- med_int numdt=0,numo=0,nbrefmaa;
- med_float dt=0.0;
- med_booleen local;
- //char pflname[MED_TAILLE_NOM+1]="";
- //char locname[MED_TAILLE_NOM+1]="";
- char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
- char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nbFields=MEDnField(fid);
+ //
+ med_field_type typcha;
+ INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_bool localmesh;
//
for(int i=0;i<nbFields;i++)
{
- med_int ncomp=MEDnChamp(fid,i+1);
- char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
- char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
- std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
- delete [] comp;
- delete [] unit;
+ med_int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
+ med_int nbPdt;
+ INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
+ std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
if(curFieldName==fieldName)
- {
- bool found=false;
- for(int j=0;j<MED_NBR_GEOMETRIE_MAILLE+2 && !found;j++)
- {
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_MAILLE,typmai[j]);
- for(int k=0;k<nbPdt;k++)
- {
- MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
- std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
- if(std::find(ret.begin(),ret.end(),curMeshName)==ret.end())
- ret.push_back(curMeshName);
- }
- }
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE);
- for(int k=0;k<nbPdt;k++)
- {
- MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
- std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
- if(std::find(ret.begin(),ret.end(),curMeshName)==ret.end())
- ret.push_back(curMeshName);
- }
- }
+ ret.push_back(meshName);
}
- delete [] maa_ass;
- delete [] dt_unit;
- delete [] nomcha;
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
std::vector<std::string> MEDLoader::GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
{
CheckFileForRead(fileName);
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nfam=MEDnFam(fid,(char *)meshName);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nfam=MEDnFamily(fid,meshName);
std::vector<std::string> ret(nfam);
- char nomfam[MED_TAILLE_NOM+1];
+ char nomfam[MED_NAME_SIZE+1];
med_int numfam;
for(int i=0;i<nfam;i++)
{
- int ngro=MEDnGroupe(fid,(char *)meshName,i+1);
- med_int natt=MEDnAttribut(fid,(char *)meshName,i+1);
- med_int *attide=new int[natt];
- med_int *attval=new int[natt];
- char *attdes=new char[MED_TAILLE_DESC*natt+1];
- char *gro=new char[MED_TAILLE_LNOM*ngro+1];
- MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro);
+ int ngro=MEDnFamilyGroup(fid,meshName,i+1);
+ med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
+ INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
+ INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
+ MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
ret[i]=cur;
- delete [] attdes;
- delete [] gro;
- delete [] attide;
- delete [] attval;
}
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
+
std::vector<std::string> MEDLoader::GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception)
{
CheckFileForRead(fileName);
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nfam=MEDnFam(fid,(char *)meshName);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nfam=MEDnFamily(fid,meshName);
std::vector<std::string> ret;
- char nomfam[MED_TAILLE_NOM+1];
+ char nomfam[MED_NAME_SIZE+1];
med_int numfam;
for(int i=0;i<nfam;i++)
{
- int ngro=MEDnGroupe(fid,(char *)meshName,i+1);
- med_int natt=MEDnAttribut(fid,(char *)meshName,i+1);
- INTERP_KERNEL::AutoPtr<med_int> attide=new int[natt];
- INTERP_KERNEL::AutoPtr<med_int> attval=new int[natt];
- INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_TAILLE_DESC*natt+1];
- INTERP_KERNEL::AutoPtr<char> gro=new char[MED_TAILLE_LNOM*ngro+1];
- MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro);
+ int ngro=MEDnFamilyGroup(fid,meshName,i+1);
+ med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
+ INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
+ INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
+ MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
for(int j=0;j<ngro;j++)
{
- std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
+ std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
if(cur2==grpName)
ret.push_back(cur);
}
}
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
std::vector<std::string> MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception)
{
CheckFileForRead(fileName);
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nfam=MEDnFam(fid,(char *)meshName);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nfam=MEDnFamily(fid,meshName);
std::vector<std::string> ret;
- char nomfam[MED_TAILLE_NOM+1];
+ char nomfam[MED_NAME_SIZE+1];
med_int numfam;
bool found=false;
for(int i=0;i<nfam && !found;i++)
{
- int ngro=MEDnGroupe(fid,(char *)meshName,i+1);
- med_int natt=MEDnAttribut(fid,(char *)meshName,i+1);
- INTERP_KERNEL::AutoPtr<med_int> attide=new int[natt];
- INTERP_KERNEL::AutoPtr<med_int> attval=new int[natt];
- INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_TAILLE_DESC*natt+1];
- INTERP_KERNEL::AutoPtr<char> gro=new char[MED_TAILLE_LNOM*ngro+1];
- MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro);
+ int ngro=MEDnFamilyGroup(fid,meshName,i+1);
+ med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
+ INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
+ INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
+ MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
found=(cur==famName);
if(found)
for(int j=0;j<ngro;j++)
{
- std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
+ std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
ret.push_back(cur);
}
}
- MEDfermer(fid);
+ MEDfileClose(fid);
if(!found)
{
std::ostringstream oss;
}
return ret;
}
+
std::vector<std::string> MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
{
CheckFileForRead(fileName);
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nfam=MEDnFam(fid,(char *)meshName);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nfam=MEDnFamily(fid,meshName);
std::vector<std::string> ret;
- char nomfam[MED_TAILLE_NOM+1];
+ char nomfam[MED_NAME_SIZE+1];
med_int numfam;
for(int i=0;i<nfam;i++)
{
- int ngro=MEDnGroupe(fid,(char *)meshName,i+1);
- med_int natt=MEDnAttribut(fid,(char *)meshName,i+1);
- med_int *attide=new int[natt];
- med_int *attval=new int[natt];
- char *attdes=new char[MED_TAILLE_DESC*natt+1];
- char *gro=new char[MED_TAILLE_LNOM*ngro+1];
- MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro);
+ int ngro=MEDnFamilyGroup(fid,meshName,i+1);
+ med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
+ INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
+ INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
+ MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
for(int j=0;j<ngro;j++)
{
- std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
+ std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
if(std::find(ret.begin(),ret.end(),cur)==ret.end())
ret.push_back(cur);
}
- delete [] attdes;
- delete [] gro;
- delete [] attide;
- delete [] attval;
}
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const char *fileName, const char *fieldName, const char *meshName) throw(INTERP_KERNEL::Exception)
{
CheckFileForRead(fileName);
std::vector<ParaMEDMEM::TypeOfField> ret;
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nbFields=MEDnChamp(fid,0);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nbFields=MEDnField(fid);
//
- med_type_champ typcha;
+ med_field_type typcha;
//med_int nbpdtnor=0,pflsize,*pflval,lnsize;
- med_int ngauss=0;
- med_int numdt=0,numo=0,nbrefmaa;
+ med_int numdt=0,numo=0;
med_float dt=0.0;
- med_booleen local;
- //char pflname[MED_TAILLE_NOM+1]="";
- //char locname[MED_TAILLE_NOM+1]="";
- char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
- char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ //char pflname[MED_NAME_SIZE+1]="";
+ //char locname[MED_NAME_SIZE+1]="";
+ char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_bool localmesh;
//
for(int i=0;i<nbFields;i++)
{
- med_int ncomp=MEDnChamp(fid,i+1);
- char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
- char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
- std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
- delete [] comp;
- delete [] unit;
- if(curFieldName==fieldName)
+ med_int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
+ med_int nbPdt;
+ MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
+ std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
+ if(curMeshName==meshName)
{
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE);
- if(nbPdt>0)
+ if(curFieldName==fieldName)
{
- bool found=false;
- for(int i=0;i<nbPdt && !found;i++)
+ if(nbPdt>0)
{
- MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
- std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
- if(curMeshName==meshName)
+ bool found=false;
+ for(int i=0;i<nbPdt && !found;i++)
{
- ret.push_back(ON_NODES);
- found=true;
+ MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
+ med_int nbOfVal=MEDfieldnValue(fid,nomcha,numdt,numo,MED_NODE,MED_NONE);
+ if(nbOfVal>0)
+ {
+ ret.push_back(ON_NODES);
+ found=true;
+ }
}
}
- }
- bool found=false;
- for(int j=0;j<MED_NBR_GEOMETRIE_MAILLE+2 && !found;j++)
- {
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_MAILLE,typmai[j]);
- if(nbPdt>0)
+ bool found=false;
+ for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
{
- MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
- std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
- if(curMeshName==meshName)
+ if(nbPdt>0)
{
- found=true;
- ret.push_back(ON_CELLS);
+ MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
+ med_int nbOfVal=MEDfieldnValue(fid,nomcha,numdt,numo,MED_CELL,typmai[j]);
+ if(nbOfVal>0)
+ {
+ found=true;
+ ret.push_back(ON_CELLS);
+ }
}
}
}
}
}
delete [] maa_ass;
- delete [] dt_unit;
delete [] nomcha;
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
{
CheckFileForRead(fileName);
std::vector<std::string> ret;
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nbFields=MEDnChamp(fid,0);
- med_type_champ typcha;
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nbFields=MEDnField(fid);
+ med_field_type typcha;
for(int i=0;i<nbFields;i++)
{
- med_int ncomp=MEDnChamp(fid,i+1);
- char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
- char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
- char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
+ med_int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
+ med_int nbPdt;
+ med_bool localmesh;
+ MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
ret.push_back(std::string(nomcha));
- delete [] nomcha;
- delete [] comp;
- delete [] unit;
}
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
{
CheckFileForRead(fileName);
std::vector<std::string> ret;
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nbFields=MEDnChamp(fid,0);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nbFields=MEDnField(fid);
//
- med_type_champ typcha;
- //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
- med_int ngauss=0;
- med_int numdt=0,numo=0,nbrefmaa;
- med_float dt=0.0;
- med_booleen local;
- //char pflname[MED_TAILLE_NOM+1]="";
- //char locname[MED_TAILLE_NOM+1]="";
- char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
- char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ med_field_type typcha;
+ char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
//
for(int i=0;i<nbFields;i++)
{
- med_int ncomp=MEDnChamp(fid,i+1);
- char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
- char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
- std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
- delete [] comp;
- delete [] unit;
- //
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE);
- bool found=false;
- if(nbPdt>0)
- {
- for(int i=0;i<nbPdt && !found;i++)
- {
- MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,i+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
- std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
- if(curMeshName==meshName)
- {
- found=true;
- ret.push_back(curFieldName);
- }
- }
- }
+ med_int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
+ med_int nbPdt;
+ med_bool localmesh;
+ MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
+ std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
//
- for(int j=0;j<MED_NBR_GEOMETRIE_MAILLE+2 && !found;j++)
- {
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_MAILLE,typmai[j]);
- if(nbPdt>0)
- {
- MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
- std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
- if(curMeshName==meshName)
- {
- found=true;
- ret.push_back(curFieldName);
- }
- }
- }
+ if(curMeshName==meshName)
+ ret.push_back(curFieldName);
}
delete [] maa_ass;
- delete [] dt_unit;
delete [] nomcha;
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
{
CheckFileForRead(fileName);
std::vector<std::string> ret;
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nbFields=MEDnChamp(fid,0);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nbFields=MEDnField(fid);
//
- med_type_champ typcha;
+ med_field_type typcha;
//med_int nbpdtnor=0,pflsize,*pflval,lnsize;
- med_int ngauss=0;
- med_int numdt=0,numo=0,nbrefmaa;
+ med_int numdt=0,numo=0;
med_float dt=0.0;
- med_booleen local;
- //char pflname[MED_TAILLE_NOM+1]="";
- //char locname[MED_TAILLE_NOM+1]="";
- char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
- char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ //char pflname[MED_NAME_SIZE+1]="";
+ //char locname[MED_NAME_SIZE+1]="";
+ INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_bool localmesh;
+ med_int nbPdt;
//
for(int i=0;i<nbFields;i++)
{
- med_int ncomp=MEDnChamp(fid,i+1);
- char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
- char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
- std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
- delete [] comp;
- delete [] unit;
- bool found=false;
- for(int j=0;j<MED_NBR_GEOMETRIE_MAILLE+2 && !found;j++)
+ med_int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
+ MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
+ std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
+ if(curMeshName==meshName)
{
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_MAILLE,typmai[j]);
- if(nbPdt>0)
+ bool found=false;
+ for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
{
- MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
- std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
- if(curMeshName==meshName)
+ if(nbPdt>0)
{
- found=true;
- ret.push_back(curFieldName);
+ MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
+ med_int nbOfVal=MEDfieldnValue(fid,nomcha,numdt,numo,MED_CELL,typmai[j]);
+ if(nbOfVal>0)
+ {
+ found=true;
+ ret.push_back(curFieldName);
+ }
}
}
}
}
- delete [] maa_ass;
- delete [] dt_unit;
- delete [] nomcha;
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
{
CheckFileForRead(fileName);
std::vector<std::string> ret;
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nbFields=MEDnChamp(fid,0);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nbFields=MEDnField(fid);
//
- med_type_champ typcha;
- med_int ngauss=0;
- med_int numdt=0,numo=0,nbrefmaa;
+ med_field_type typcha;
+ med_int numdt=0,numo=0;
med_float dt=0.0;
- med_booleen local;
- char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
- char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_bool localmesh;
//
for(int i=0;i<nbFields;i++)
{
- med_int ncomp=MEDnChamp(fid,i+1);
- char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
- char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
- std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
- delete [] comp;
- delete [] unit;
+ med_int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
+ med_int nbPdt;
+ MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
+ std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
bool found=false;
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE);
if(nbPdt>0)
{
- MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
- std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_TAILLE_NOM+1);
- if(curMeshName==meshName)
+ MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
+ med_int nbOfVal=MEDfieldnValue(fid,nomcha,numdt,numo,MED_NODE,MED_NONE);
+ if(curMeshName==meshName && nbOfVal>0)
{
found=true;
ret.push_back(curFieldName);
}
}
}
- delete [] maa_ass;
- delete [] dt_unit;
- delete [] nomcha;
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
{
CheckFileForRead(fileName);
std::string meshNameCpp(meshName);
- std::vector< std::pair< std::pair<int,int>, double> > ret;
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nbFields=MEDnChamp(fid,0);
+ std::vector< std::pair< std::pair<int,int>, double > > ret;
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nbFields=MEDnField(fid);
//
- med_type_champ typcha;
- med_int ngauss=0;
- med_int numdt=0,numo=0,nbrefmaa;
+ med_field_type typcha;
+ med_int numdt=0,numo=0;
med_float dt=0.0;
- med_booleen local;
- char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
- char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_bool localmesh;
//
for(int i=0;i<nbFields;i++)
{
- med_int ncomp=MEDnChamp(fid,i+1);
- char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
- char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
- std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
- delete [] comp;
- delete [] unit;
+ med_int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
+ med_int nbPdt;
+ MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
if(curFieldName==fieldName)
{
bool found=false;
- for(int j=0;j<MED_NBR_GEOMETRIE_MAILLE+2 && !found;j++)
+ for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
{
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_MAILLE,typmai[j]);
for(int k=0;k<nbPdt;k++)
{
- MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
+ med_int nbOfVal=MEDfieldnValue(fid,nomcha,numdt,numo,MED_CELL,typmai[j]);
std::string maa_ass_cpp(maa_ass);
- if(meshNameCpp==maa_ass_cpp)
+ if(meshNameCpp==maa_ass_cpp && nbOfVal>0)
{
found=true;
ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
}
}
}
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE);
for(int k=0;k<nbPdt;k++)
{
- MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
+ med_int nbOfVal=MEDfieldnValue(fid,nomcha,numdt,numo,MED_NODE,MED_NONE);
std::string maa_ass_cpp(maa_ass);
- if(meshNameCpp==maa_ass_cpp)
- ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
+ if(meshNameCpp==maa_ass_cpp && nbOfVal>0)
+ {
+ found=true;
+ ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
+ }
}
}
}
- delete [] maa_ass;
- delete [] dt_unit;
- delete [] nomcha;
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
double MEDLoader::GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
{
CheckFileForRead(fileName);
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nbFields=MEDnChamp(fid,0);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nbFields=MEDnField(fid);
//
- med_type_champ typcha;
- med_int ngauss=0;
- med_int numdt=0,numo=0,nbrefmaa;
+ med_field_type typcha;
+ med_int numdt=0,numo=0;
med_float dt=0.0;
- med_booleen local;
- char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
- char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ med_bool local;
+ INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
//
bool found=false;
bool found2=false;
double ret=std::numeric_limits<double>::max();
for(int i=0;i<nbFields && !found;i++)
{
- med_int ncomp=MEDnChamp(fid,i+1);
- char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
- char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
- std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
- delete [] comp;
- delete [] unit;
+ med_int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
+ med_int nbPdt;
+ MEDfieldInfo(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
if(curFieldName==fieldName)
{
found=true;
- for(int j=0;j<MED_NBR_GEOMETRIE_MAILLE+2 && !found2;j++)
+ for(int j=0;j<MED_N_CELL_FIXED_GEO && !found2;j++)
{
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_MAILLE,typmai[j]);
for(int k=0;k<nbPdt;k++)
{
- MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
- if(numdt==iteration && numo==order)
- {
- found2=true;
- ret=dt;
- }
- }
- }
- if(!found2)
- {
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE);
- for(int k=0;k<nbPdt && !found2;k++)
- {
- MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
if(numdt==iteration && numo==order)
{
found2=true;
}
}
}
- delete [] maa_ass;
- delete [] dt_unit;
- delete [] nomcha;
- MEDfermer(fid);
+ MEDfileClose(fid);
if(!found || !found2)
{
std::ostringstream oss;
CheckFileForRead(fileName);
std::string meshNameCpp(meshName);
std::vector< std::pair<int,int> > ret;
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nbFields=MEDnChamp(fid,0);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nbFields=MEDnField(fid);
//
- med_type_champ typcha;
- med_int ngauss=0;
- med_int numdt=0,numo=0,nbrefmaa;
+ med_field_type typcha;
+ med_int numdt=0,numo=0;
med_float dt=0.0;
- med_booleen local;
- char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
- char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_bool localmesh;
//
for(int i=0;i<nbFields;i++)
{
- med_int ncomp=MEDnChamp(fid,i+1);
- char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
- char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
- std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
- delete [] comp;
- delete [] unit;
+ med_int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
+ med_int nbPdt;
+ MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
if(curFieldName==fieldName)
{
bool found=false;
- for(int j=0;j<MED_NBR_GEOMETRIE_MAILLE+2 && !found;j++)
+ for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
{
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_MAILLE,typmai[j]);
for(int k=0;k<nbPdt;k++)
{
- MEDpasdetempsInfo(fid,nomcha,MED_MAILLE,typmai[j],k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
+ med_int nbOfVal=MEDfieldnValue(fid,nomcha,numdt,numo,MED_CELL,typmai[j]);
std::string maa_ass_cpp(maa_ass);
- if(meshNameCpp==maa_ass_cpp)
+ if(meshNameCpp==maa_ass_cpp && nbOfVal>0)
{
found=true;
ret.push_back(std::make_pair(numdt,numo));
}
}
}
- delete [] maa_ass;
- delete [] dt_unit;
- delete [] nomcha;
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
CheckFileForRead(fileName);
std::string meshNameCpp(meshName);
std::vector< std::pair<int,int> > ret;
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nbFields=MEDnChamp(fid,0);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nbFields=MEDnField(fid);
//
- med_type_champ typcha;
- med_int ngauss=0;
- med_int numdt=0,numo=0,nbrefmaa;
+ med_field_type typcha;
+ med_int numdt=0,numo=0;
med_float dt=0.0;
- med_booleen local;
- char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
- char *nomcha=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_bool localmesh;
//
for(int i=0;i<nbFields;i++)
{
- med_int ncomp=MEDnChamp(fid,i+1);
- char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
- char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
- std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
- delete [] comp;
- delete [] unit;
+ med_int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
+ med_int nbPdt;
+ MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
if(curFieldName==fieldName)
{
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,MED_NOEUD,MED_NONE);
for(int k=0;k<nbPdt;k++)
{
- MEDpasdetempsInfo(fid,nomcha,MED_NOEUD,MED_NONE,k+1, &ngauss, &numdt, &numo, dt_unit,&dt, maa_ass, &local, &nbrefmaa);
+ MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
+ med_int nbOfVal=MEDfieldnValue(fid,nomcha,numdt,numo,MED_NODE,MED_NONE);
std::string maa_ass_cpp(maa_ass);
- if(meshNameCpp==maa_ass_cpp)
+ if(meshNameCpp==maa_ass_cpp && nbOfVal>0)
{
ret.push_back(std::make_pair(numdt,numo));
}
}
}
}
- delete [] maa_ass;
- delete [] dt_unit;
- delete [] nomcha;
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
double& time, std::vector<std::string>& infos)
{
time=0.;
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nbFields=MEDnChamp(fid,0);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nbFields=MEDnField(fid);
//
- med_type_champ typcha;
- char nomcha[MED_TAILLE_NOM+1]="";
- char pflname [MED_TAILLE_NOM+1]="";
- char locname [MED_TAILLE_NOM+1]="";
- std::map<ParaMEDMEM::TypeOfField, med_entite_maillage> tabEnt;
- std::map<ParaMEDMEM::TypeOfField, med_geometrie_element *> tabType;
+ med_field_type typcha;
+ char nomcha[MED_NAME_SIZE+1]="";
+ char pflname [MED_NAME_SIZE+1]="";
+ char locname [MED_NAME_SIZE+1]="";
+ std::map<ParaMEDMEM::TypeOfField, med_entity_type> tabEnt;
+ std::map<ParaMEDMEM::TypeOfField, med_geometry_type *> tabType;
std::map<ParaMEDMEM::TypeOfField, int> tabTypeLgth;
- tabEnt[ON_CELLS]=MED_MAILLE;
+ med_bool localmesh;
+ tabEnt[ON_CELLS]=MED_CELL;
tabType[ON_CELLS]=typmai;
- tabTypeLgth[ON_CELLS]=MED_NBR_GEOMETRIE_MAILLE+2;
- tabEnt[ON_NODES]=MED_NOEUD;
+ tabTypeLgth[ON_CELLS]=MED_N_CELL_FIXED_GEO;
+ tabEnt[ON_NODES]=MED_NODE;
tabType[ON_NODES]=typmainoeud;
tabTypeLgth[ON_NODES]=1;
- tabEnt[ON_GAUSS_PT]=MED_MAILLE;
+ tabEnt[ON_GAUSS_PT]=MED_CELL;
tabType[ON_GAUSS_PT]=typmai;
- tabTypeLgth[ON_GAUSS_PT]=MED_NBR_GEOMETRIE_MAILLE+2;
- tabEnt[ON_GAUSS_NE]=MED_MAILLE;
+ tabTypeLgth[ON_GAUSS_PT]=MED_N_CELL_FIXED_GEO;
+ tabEnt[ON_GAUSS_NE]=MED_NODE_ELEMENT;
tabType[ON_GAUSS_NE]=typmai;
- tabTypeLgth[ON_GAUSS_NE]=MED_NBR_GEOMETRIE_MAILLE+2;
+ tabTypeLgth[ON_GAUSS_NE]=MED_N_CELL_FIXED_GEO;
//
for(int i=0;i<nbFields;i++)
{
- med_int ncomp=MEDnChamp(fid,i+1);
- char *comp=new char[ncomp*MED_TAILLE_PNOM+1];
- char *unit=new char[ncomp*MED_TAILLE_PNOM+1];
- MEDchampInfo(fid,i+1,nomcha,&typcha,comp,unit,ncomp);
- std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_TAILLE_NOM+1);
+ med_int ncomp=MEDfieldnComponent(fid,i+1);
+ INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
+ INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ med_int nbPdt;
+ MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
+ std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
+ if(curMeshName!=meshName)
+ {
+ MEDfileClose(fid);
+ throw INTERP_KERNEL::Exception("Invalid meshname on field !");
+ }
+ std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
if(curFieldName==fieldName)
{
infos.resize(ncomp);
for(int i=0;i<ncomp;i++)
- infos[i]=MEDLoaderBase::buildUnionUnit(comp+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM,unit+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
+ infos[i]=MEDLoaderBase::buildUnionUnit(comp+i*MED_SNAME_SIZE,MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
bool found=false;
+ bool found2=false;
+ med_int numdt=0,numo=0;
+ med_float dt=0.0;
+ for(int k=0;k<nbPdt && !found2;k++)
+ {
+ MEDfieldComputingStepInfo(fid,fieldName,k+1,&numdt,&numo,&dt);
+ found2=(numdt==iteration && numo==order);
+ if(found2)
+ time=dt;
+ }
+ if(!found2)
+ {
+ std::ostringstream oss; oss << "FieldDouble in file \""<< fileName<< "\" with name \"" << fieldName << "\" on mesh \"" << meshName;
+ oss << "\" does not have such time step : iteration=" << iteration << " order=" << order << std::endl;
+ MEDfileClose(fid);
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
for(int j=0;j<tabTypeLgth[typeOfOutField] && !found;j++)
{
- med_int nbPdt=MEDnPasdetemps(fid,nomcha,tabEnt[typeOfOutField],typmai[j]);
if(nbPdt>0)
{
- int nval=MEDnVal(fid,(char *)fieldName,tabEnt[typeOfOutField],tabType[typeOfOutField][j],iteration,order,(char *)meshName,MED_COMPACT);
- double *valr=new double[ncomp*nval];
- //
- med_int ngauss=0;
- med_int numdt=0,numo=0,nbrefmaa;
- char *dt_unit=MEDLoaderBase::buildEmptyString(MED_TAILLE_PNOM);
- char *maa_ass=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- med_float dt=0.0;
- med_booleen local;
- med_int nbPdt=MEDnPasdetemps(fid,(char *)fieldName,tabEnt[typeOfOutField],tabType[typeOfOutField][j]);
- bool found2=false;
- for(int k=0;k<nbPdt && !found2;k++)
+ int profilesize,nbi;
+ int nval=MEDfieldnValueWithProfile(fid,fieldName,numdt,numo,tabEnt[typeOfOutField],tabType[typeOfOutField][j],1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi);
+ if(nval>0)
{
- MEDpasdetempsInfo(fid,(char *)fieldName,tabEnt[typeOfOutField],tabType[typeOfOutField][j],k+1,&ngauss,
- &numdt,&numo,dt_unit,&dt,maa_ass,&local,&nbrefmaa);
- found2=(numdt==iteration && numo==order);
- if(found2)
- time=dt;
- }
- if(!found2)
- {
- std::ostringstream oss; oss << "FieldDouble in file \""<< fileName<< "\" with name \"" << fieldName << "\" on mesh \"" << meshName;
- oss << "\" does not have such time step : iteration=" << iteration << " order=" << order << std::endl;
- delete [] valr;
- delete [] comp;
- delete [] unit;
- delete [] dt_unit;
- delete [] maa_ass;
- MEDfermer(fid);
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- MEDchampLire(fid,(char *)meshName,(char *)fieldName,(unsigned char*)valr,MED_FULL_INTERLACE,MED_ALL,locname,
- pflname,MED_COMPACT,tabEnt[typeOfOutField],tabType[typeOfOutField][j],iteration,order);
- std::string tmp(locname);
- if((locname[0]!='\0' && (typeOfOutField!=ON_GAUSS_PT && typeOfOutField!=ON_GAUSS_NE))
- || (tmp!=MED_GAUSS_ELNO && typeOfOutField==ON_GAUSS_NE)
- || (locname[0]=='\0' && typeOfOutField==ON_GAUSS_PT)
- || (tmp==MED_GAUSS_ELNO && typeOfOutField==ON_GAUSS_PT))
- {
- delete [] dt_unit;
- delete [] maa_ass;
- delete [] valr;
- continue;
- }
- int *pfl=0;
- if(pflname[0]!='\0')
- {
- pfl=new int[nval];
- MEDprofilLire(fid,pfl,pflname);
+ double *valr=new double[ncomp*nval*nbi];
+ MEDfieldValueWithProfileRd(fid,fieldName,iteration,order,tabEnt[typeOfOutField],tabType[typeOfOutField][j],MED_COMPACT_PFLMODE,
+ pflname,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(unsigned char*)valr);
+ std::string tmp(locname);
+ if((locname[0]!='\0' && (typeOfOutField!=ON_GAUSS_PT))
+ || (locname[0]=='\0' && typeOfOutField==ON_GAUSS_PT))
+ {
+ delete [] valr;
+ continue;
+ }
+ INTERP_KERNEL::AutoPtr<int> pfl=0;
+ if(pflname[0]!='\0')
+ {
+ pfl=new int[nval];
+ MEDprofileRd(fid,pflname,pfl);
+ }
+ field.push_back(MEDLoader::MEDFieldDoublePerCellType(typmai2[j],valr,ncomp,nval*nbi,pfl,locname));
}
- field.push_back(MEDLoader::MEDFieldDoublePerCellType(typmai2[j],valr,ncomp,nval,pfl,locname));
- delete [] pfl;
- delete [] dt_unit;
- delete [] maa_ass;
}
}
}
- delete [] comp;
- delete [] unit;
}
- MEDfermer(fid);
+ MEDfileClose(fid);
}
std::vector<int> MEDLoaderNS::getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector<std::string>& fams)
{
std::vector<int> ret;
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nfam=MEDnFam(fid,(char *)meshName);
- char nomfam[MED_TAILLE_NOM+1];
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nfam=MEDnFamily(fid,meshName);
+ char nomfam[MED_NAME_SIZE+1];
med_int numfam;
for(int i=0;i<nfam;i++)
{
- int ngro=MEDnGroupe(fid,(char *)meshName,i+1);
- med_int natt=MEDnAttribut(fid,(char *)meshName,i+1);
- med_int *attide=new int[natt];
- med_int *attval=new int[natt];
- char *attdes=new char[MED_TAILLE_DESC*natt+1];
- char *gro=new char[MED_TAILLE_LNOM*ngro+1];
- MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro);
+ int ngro=MEDnFamilyGroup(fid,meshName,i+1);
+ med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
+ INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
+ INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
+ MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
if(std::find(fams.begin(),fams.end(),cur)!=fams.end())
ret.push_back(numfam);
- delete [] attdes;
- delete [] gro;
- delete [] attide;
- delete [] attval;
}
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
std::vector<int> MEDLoaderNS::getIdsFromGroups(const char *fileName, const char *meshName, const std::vector<std::string>& grps)
{
std::vector<int> ret;
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
- med_int nfam=MEDnFam(fid,(char *)meshName);
- char nomfam[MED_TAILLE_NOM+1];
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
+ med_int nfam=MEDnFamily(fid,meshName);
+ char nomfam[MED_NAME_SIZE+1];
med_int numfam;
for(int i=0;i<nfam;i++)
{
- int ngro=MEDnGroupe(fid,(char *)meshName,i+1);
- med_int natt=MEDnAttribut(fid,(char *)meshName,i+1);
- med_int *attide=new int[natt];
- med_int *attval=new int[natt];
- char *attdes=new char[MED_TAILLE_DESC*natt+1];
- char *gro=new char[MED_TAILLE_LNOM*ngro+1];
- MEDfamInfo(fid,(char *)meshName,i+1,nomfam,&numfam,attide,attval,attdes,&natt,gro,&ngro);
+ int ngro=MEDnFamilyGroup(fid,meshName,i+1);
+ med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
+ INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
+ INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
+ INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
+ MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
for(int j=0;j<ngro;j++)
{
- std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_TAILLE_LNOM,MED_TAILLE_LNOM);
+ std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
if(std::find(grps.begin(),grps.end(),cur)!=grps.end())
{
ret.push_back(numfam);
break;
}
}
- delete [] attdes;
- delete [] gro;
- delete [] attide;
- delete [] attval;
}
- MEDfermer(fid);
+ MEDfileClose(fid);
return ret;
}
/*!
* This methods allows to merger all entities and to considerate only cell types.
*/
-void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entite_maillage& whichEntity)
+void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
{
if(nbOfElemCell>=nbOfElemFace)
{
- whichEntity=MED_MAILLE;
+ whichEntity=MED_CELL;
nbOfElem=nbOfElemCell;
}
else
{
- whichEntity=MED_FACE;
+ whichEntity=MED_CELL;
nbOfElem=nbOfElemFace;
}
}
int MEDLoaderNS::readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector<int>& possibilities)
{
possibilities.clear();
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
int ret;
std::set<int> poss;
- char nommaa[MED_TAILLE_NOM+1];
- char maillage_description[MED_TAILLE_DESC+1];
- med_maillage type_maillage;
- med_int Mdim;
+ char nommaa[MED_NAME_SIZE+1];
+ char maillage_description[MED_COMMENT_SIZE+1];
+ med_mesh_type type_maillage;
+ med_int Sdim,Mdim;
std::string trueMeshName;
med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
- MEDmaaInfo(fid,meshId,nommaa,&Mdim,&type_maillage,maillage_description);
- for(int i=0;i<MED_NBR_GEOMETRIE_MAILLE;i++)
- {
- med_geometrie_element curMedType=typmai[i];
- int curNbOfElemM=MEDnEntMaa(fid,nommaa,MED_CONN,MED_MAILLE,curMedType,MED_NOD);
- int curNbOfElemF=MEDnEntMaa(fid,nommaa,MED_CONN,MED_FACE,curMedType,MED_NOD);
+ INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ med_sorting_type sortingType;
+ med_int nstep;
+ med_axis_type axisType;
+ int naxis=MEDmeshnAxis(fid,meshId);
+ INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
+ MEDmeshInfo(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit);
+ // limitation
+ if(nstep!=1)
+ {
+ throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
+ }
+ med_int numdt,numit;
+ med_float dt;
+ MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
+ // endlimitation
+ for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
+ {
+ med_geometry_type curMedType=typmai[i];
+ med_bool changement,transformation;
+ int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
+ int curNbOfElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);//limitation
int curNbOfElem;
- med_entite_maillage whichEntity;
+ med_entity_type whichEntity;
MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
if(curNbOfElem>0)
{
poss.insert(curDim);
}
}
- MEDfermer(fid);
+ MEDfileClose(fid);
if(!poss.empty())
{
ret=*poss.rbegin();
return ret;
}
-void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn)
+void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn, std::string& description)
{
- char nommaa[MED_TAILLE_NOM+1];
- char maillage_description[MED_TAILLE_DESC+1];
- med_maillage type_maillage;
+ char nommaa[MED_NAME_SIZE+1];
+ char maillage_description[MED_COMMENT_SIZE+1];
+ med_mesh_type type_maillage;
med_int Mdim;
- MEDmaaInfo(fid,meshId,nommaa,&Mdim,&type_maillage,maillage_description);
- med_int edim=MEDdimEspaceLire(fid,nommaa);
- int spaceDim=std::max((int)Mdim,(int)edim);
- int nCoords=MEDnEntMaa(fid,nommaa,MED_COOR,MED_NOEUD,(med_geometrie_element)0,(med_connectivite)0);
+ med_int Sdim;
+ INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ med_sorting_type sortingType;
+ med_int nstep;
+ med_axis_type axisType;
+ med_int numdt,numit;
+ med_float dt;
+ med_bool changement,transformation;
+ // endlimitation
+ Sdim=MEDmeshnAxis(fid,1);
+ INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(Sdim*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(Sdim*MED_SNAME_SIZE);
+ MEDmeshInfo(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,comp,unit);
+ description=MEDLoaderBase::buildStringFromFortran(maillage_description,sizeof(maillage_description));
+ MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
+ int spaceDim=std::max((int)Mdim,(int)Sdim);
+ int nCoords=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
+ // limitation
+ if(nstep!=1)
+ {
+ throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
+ }
coords=DataArrayDouble::New();
coords->alloc(nCoords,spaceDim);
double *coordsPtr=coords->getPointer();
- med_repere repere;
- char *comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
- char *unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
- MEDcoordLire(fid,nommaa,spaceDim,coordsPtr,MED_FULL_INTERLACE,MED_ALL,NULL,0,&repere,comp,unit);
+ MEDmeshNodeCoordinateRd(fid,nommaa,numdt,numit,MED_FULL_INTERLACE,coordsPtr);
for(int i=0;i<spaceDim;i++)
{
- std::string n,u;
- std::string info=MEDLoaderBase::buildUnionUnit(comp+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM,unit+i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
+ std::string info=MEDLoaderBase::buildUnionUnit(comp+i*MED_SNAME_SIZE,MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
coords->setInfoOnComponent(i,info.c_str());
}
- delete [] comp;
- delete [] unit;
- med_booleen inoele, inuele;
- for(int i=0;i<MED_NBR_GEOMETRIE_MAILLE;i++)
+ for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
{
- med_geometrie_element curMedType=typmai[i];
- med_entite_maillage whichEntity;
- int curNbOfElemM=MEDnEntMaa(fid,nommaa,MED_CONN,MED_MAILLE,curMedType,MED_NOD);
- int curNbOfElemF=MEDnEntMaa(fid,nommaa,MED_CONN,MED_FACE,curMedType,MED_NOD);
+ med_geometry_type curMedType=typmai[i];
+ med_entity_type whichEntity;
+ int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
+ int curNbOfElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);//limitation
int curNbOfElem;
MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
if(curNbOfElem>0)
int *connTab=new int[(curMedType%100)*curNbOfElem];
int *fam=new int[curNbOfElem];
MEDLoader::MEDConnOfOneElemType elem(typmai2[i],connTab,0,fam,curNbOfElem,-1);
- int *tmp=new int[curNbOfElem];
- char *noms=new char[MED_TAILLE_PNOM*curNbOfElem+1];
- MEDelementsLire(fid,nommaa,Mdim,connTab,MED_FULL_INTERLACE,noms,&inoele,tmp,&inuele,fam,curNbOfElem,whichEntity,curMedType,MED_NOD);
- delete [] tmp;
+ char *noms=new char[MED_SNAME_SIZE*curNbOfElem+1];
+ med_bool withname=MED_FALSE,withnumber=MED_FALSE,withfam=MED_FALSE;
+ int *globArr=new int[curNbOfElem];
+ MEDmeshElementRd(fid,nommaa,numdt,numit,whichEntity,curMedType,MED_NODAL,MED_FULL_INTERLACE,connTab,&withname,noms,&withnumber,globArr,&withfam,fam);
+ if(!withfam)
+ std::fill(fam,fam+curNbOfElem,0);
delete [] noms;
//trying to read global numbering
- int *globArr=new int[curNbOfElem];
- if(MEDnumLire(fid,nommaa,globArr,curNbOfElem,whichEntity,curMedType)==0)
+ if(withnumber)
elem.setGlobal(globArr);
else
delete [] globArr;
+ //limitation manage withfam==false
conn.push_back(elem);
}
}
int curNbOfPolyElem;
- int curNbOfPolyElemM=MEDnEntMaa(fid,nommaa,MED_CONN,MED_MAILLE,MED_POLYGONE,MED_NOD);
- int curNbOfPolyElemF=MEDnEntMaa(fid,nommaa,MED_CONN,MED_FACE,MED_POLYGONE,MED_NOD);
- med_entite_maillage whichPolyEntity;
+ int curNbOfPolyElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1;
+ int curNbOfPolyElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1;//limitation
+ med_entity_type whichPolyEntity;
MEDLoaderNS::dispatchElems(curNbOfPolyElemM,curNbOfPolyElemF,curNbOfPolyElem,whichPolyEntity);
if(curNbOfPolyElem>0)
{
- med_int arraySize;
- MEDpolygoneInfo(fid,nommaa,whichPolyEntity,MED_NOD,&arraySize);
+ med_int arraySize=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
int *index=new int[curNbOfPolyElem+1];
int *locConn=new int[arraySize];
int *fam=new int[curNbOfPolyElem];
int *globArr=new int[curNbOfPolyElem];
MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYGON,locConn,index,fam,curNbOfPolyElem,arraySize);
- MEDpolygoneConnLire(fid,nommaa,index,curNbOfPolyElem+1,locConn,whichPolyEntity,MED_NOD);
- MEDfamLire(fid,nommaa,fam,curNbOfPolyElem,whichPolyEntity,MED_POLYGONE);
- if(MEDnumLire(fid,nommaa,globArr,curNbOfPolyElem,whichPolyEntity,MED_POLYGONE)==0)
- elem.setGlobal(globArr);
+ MEDmeshPolygonRd(fid,nommaa,numdt,numit,MED_CELL,MED_NODAL,index,locConn);
+ if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
+ {
+ if(MEDmeshEntityFamilyNumberRd(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,fam)!=0)
+ std::fill(fam,fam+curNbOfPolyElem,0);
+ }
+ else
+ std::fill(fam,fam+curNbOfPolyElem,0);
+ if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
+ {
+ if(MEDmeshEntityNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYGON,globArr)==0)
+ elem.setGlobal(globArr);
+ else
+ delete [] globArr;
+ }
else
delete [] globArr;
conn.push_back(elem);
}
- curNbOfPolyElem=MEDnEntMaa(fid,nommaa,MED_CONN,MED_MAILLE,MED_POLYEDRE,MED_NOD);
+ curNbOfPolyElem=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1;
if(curNbOfPolyElem>0)
{
med_int indexFaceLgth,connFaceLgth;
- MEDpolyedreInfo(fid,nommaa,MED_NOD,&indexFaceLgth,&connFaceLgth);
- int *index=new int[curNbOfPolyElem+1];
- int *indexFace=new int[indexFaceLgth];
- int *locConn=new int[connFaceLgth];
+ indexFaceLgth=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation);
+ connFaceLgth=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
+ INTERP_KERNEL::AutoPtr<int> index=new int[curNbOfPolyElem+1];
+ INTERP_KERNEL::AutoPtr<int> indexFace=new int[indexFaceLgth];
+ INTERP_KERNEL::AutoPtr<int> locConn=new int[connFaceLgth];
int *fam=new int[curNbOfPolyElem];
int *globArr=new int[curNbOfPolyElem];
- MEDpolyedreConnLire(fid,nommaa,index,curNbOfPolyElem+1,indexFace,indexFaceLgth,locConn,MED_NOD);
- MEDfamLire(fid,nommaa,fam,curNbOfPolyElem,MED_MAILLE,MED_POLYEDRE);
+ MEDmeshPolyhedronRd(fid,nommaa,numdt,numit,MED_CELL,MED_NODAL,index,indexFace,locConn);
+ if(MEDmeshnEntity(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
+ {
+ if(MEDmeshEntityFamilyNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,fam)!=0)
+ std::fill(fam,fam+curNbOfPolyElem,0);
+ }
+ else
+ std::fill(fam,fam+curNbOfPolyElem,0);
int arraySize=connFaceLgth;
for(int i=0;i<curNbOfPolyElem;i++)
arraySize+=index[i+1]-index[i]-1;
wFinalConn=std::copy(locConn+indexFace[j]-1,locConn+indexFace[j+1]-1,wFinalConn);
}
}
- delete [] index;
- delete [] locConn;
- delete [] indexFace;
MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYHED,finalConn,finalIndex,fam,curNbOfPolyElem,arraySize);
- if(MEDnumLire(fid,nommaa,globArr,curNbOfPolyElem,MED_MAILLE,MED_POLYEDRE)==0)
- elem.setGlobal(globArr);
+ if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
+ {
+ if(MEDmeshEntityNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,globArr)==0)
+ elem.setGlobal(globArr);
+ else
+ delete [] globArr;
+ }
else
delete [] globArr;
conn.push_back(elem);
if(meshDimRelToMax>0)
throw INTERP_KERNEL::Exception("meshDimRelToMax must be <=0 !");
//Extraction data from MED file.
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
std::string trueMeshName;
med_int mid=getIdFromMeshName(fid,meshName,trueMeshName);
DataArrayDouble *coords=0;
std::list<MEDLoader::MEDConnOfOneElemType> conn;
- readUMeshDataInMedFile(fid,mid,coords,conn);
+ std::string descr;
+ readUMeshDataInMedFile(fid,mid,coords,conn,descr);
meshDimExtract=MEDLoaderNS::calculateHighestMeshDim<MEDLoader::MEDConnOfOneElemType>(conn);
meshDimExtract=meshDimExtract+meshDimRelToMax;
MEDLoaderNS::keepSpecifiedMeshDim<MEDLoader::MEDConnOfOneElemType>(conn,meshDimExtract);
MEDLoaderNS::keepTypes<MEDLoader::MEDConnOfOneElemType>(conn,typesToKeep);
- MEDfermer(fid);
+ MEDfileClose(fid);
//Put data in returned data structure.
MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
ret->setName(trueMeshName.c_str());
+ ret->setDescription(descr.c_str());
ret->setMeshDimension(meshDimExtract);
//
ret->setCoords(coords);
if(typeOfOutField==ON_CELLS)
{
if(newMesh)
- mesh2=newMesh->keepSpecifiedCells((*iter).getType(),ci);
+ mesh2=newMesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size());
else
- mesh2=mesh->keepSpecifiedCells((*iter).getType(),ci);
+ mesh2=mesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size());
}
else if(typeOfOutField==ON_NODES)
{
*/
void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& mesh, const std::vector<const DataArrayInt *>& families, bool forceFromScratch, bool &isRenumbering)
{
- med_idt fid=MEDouvrir((char *)fileName,forceFromScratch?MED_CREATION:MED_LECTURE_ECRITURE);
+ med_idt fid=MEDfileOpen(fileName,forceFromScratch?MED_ACC_CREAT:MED_ACC_RDWR);
std::string meshName(mesh[0]->getName());
if(meshName=="")
{
- MEDfermer(fid);
+ MEDfileClose(fid);
throw INTERP_KERNEL::Exception("MEDCouplingMesh must have a not null name !");
}
isRenumbering=false;
std::set<INTERP_KERNEL::NormalizedCellType> allTypes;
for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=mesh.begin();iter!=mesh.end();iter++)
{
- isRenumbering|=!(*iter)->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2);
+ isRenumbering|=!(*iter)->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
isFamilies&=(families[std::distance(mesh.begin(),iter)]!=0);
conn.push_back((*iter)->getNodalConnectivity());
connIndex.push_back((*iter)->getNodalConnectivityIndex());
const std::set<INTERP_KERNEL::NormalizedCellType>& curTypes=(*iter)->getAllTypes();
allTypes.insert(curTypes.begin(),curTypes.end());
}
- char *maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- char *desc=MEDLoaderBase::buildEmptyString(MED_TAILLE_DESC);
- MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_TAILLE_NOM,maa,MEDLoader::_TOO_LONG_STR);
- MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_TAILLE_DESC,desc,MEDLoader::_TOO_LONG_STR);
+ INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
+ MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_NAME_SIZE,maa,MEDLoader::_TOO_LONG_STR);
+ MEDLoaderBase::safeStrCpy(mesh[0]->getDescription(),MED_COMMENT_SIZE,desc,MEDLoader::_TOO_LONG_STR);
const int spaceDim=mesh[0]->getSpaceDimension();
- MEDmaaCr(fid,maa,spaceDim,MED_NON_STRUCTURE,desc);
- MEDdimEspaceCr(fid,maa,spaceDim);
+ const int meshDim=mesh[0]->getMeshDimension();
+ DataArrayDouble *arr=mesh[0]->getCoords();
+ INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
+ for(int i=0;i<spaceDim;i++)
+ {
+ std::string info=arr->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,MEDLoader::_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,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
+ }
+ MEDmeshCr(fid,maa,spaceDim,meshDim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=mesh.begin();iter!=mesh.end();iter++)
{
- for(int i=0;i<MED_NBR_GEOMETRIE_MAILLE+2;i++)
+ for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
{
- med_geometrie_element curMedType=typmai[i];
+ med_geometry_type curMedType=typmai[i];
INTERP_KERNEL::NormalizedCellType curType=typmai2[i];
if(allTypes.find(curType)!=allTypes.end())
{
std::vector<int> fam;
std::vector<int> renumber;
int nbOfElt=MEDLoaderNS::buildMEDSubConnectivityOfOneType(conn,connIndex,families,curType,medConn,medConnIndex,medConnIndex2,fam,renumber);
- if(curMedType!=MED_POLYGONE && curMedType!=MED_POLYEDRE)
- MEDconnEcr(fid,maa,(*iter)->getMeshDimension(),&medConn[0],MED_FULL_INTERLACE,nbOfElt,MED_MAILLE,curMedType,MED_NOD);
+ if(curMedType!=MED_POLYGON && curMedType!=MED_POLYHEDRON)
+ MEDmeshElementConnectivityWr(fid,maa,-1,-1,0.,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,nbOfElt,&medConn[0]);
else
{
- if(curMedType==MED_POLYGONE)
- MEDpolygoneConnEcr(fid,maa,&medConnIndex[0],medConnIndex.size(),&medConn[0],MED_MAILLE,MED_NOD);
- if(curMedType==MED_POLYEDRE)
+ if(curMedType==MED_POLYGON)
+ MEDmeshPolygonWr(fid,maa,-1,-1,0.,MED_CELL,MED_NODAL,medConnIndex.size(),&medConnIndex[0],&medConn[0]);
+ if(curMedType==MED_POLYHEDRON)
{
- MEDpolyedreConnEcr(fid,maa,&medConnIndex2[0],medConnIndex2.size(),&medConnIndex[0],medConnIndex.size(),
- &medConn[0],MED_NOD);
+ MEDmeshPolyhedronWr(fid,maa,-1,-1,0.,MED_CELL,MED_NODAL,medConnIndex2.size(),&medConnIndex2[0],medConnIndex.size(),&medConnIndex[0],
+ &medConn[0]);
}
}
if(isFamilies)
- MEDfamEcr(fid,maa,&fam[0],nbOfElt,MED_MAILLE,curMedType);
+ MEDmeshEntityFamilyNumberWr(fid,maa,-1,-1,MED_CELL,curMedType,nbOfElt,&fam[0]);
if(isRenumbering)
- MEDnumEcr(fid,maa,&renumber[0],nbOfElt,MED_MAILLE,curMedType);
+ MEDmeshEntityNumberWr(fid,maa,-1,-1,MED_CELL,curMedType,nbOfElt,&renumber[0]);
}
}
}
- char familyName[MED_TAILLE_NOM+1];
- std::fill(familyName,familyName+MED_TAILLE_NOM+1,'\0');
+ char familyName[MED_NAME_SIZE+1];
+ std::fill(familyName,familyName+MED_NAME_SIZE+1,'\0');
const char DftFamilyName[]="DftFamily";
std::copy(DftFamilyName,DftFamilyName+sizeof(DftFamilyName),familyName);
- MEDfamCr(fid,maa,familyName,0,0,0,0,0,0,0);
- DataArrayDouble *arr=mesh[0]->getCoords();
- char *comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
- char *unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_TAILLE_PNOM);
- for(int i=0;i<spaceDim;i++)
- {
- std::string info=arr->getInfoOnComponent(i);
- std::string c,u;
- MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
- MEDLoaderBase::safeStrCpy(c.c_str(),MED_TAILLE_PNOM-1,comp+i*MED_TAILLE_PNOM,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
- MEDLoaderBase::safeStrCpy(u.c_str(),MED_TAILLE_PNOM-1,unit+i*MED_TAILLE_PNOM,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
- }
- MEDcoordEcr(fid,maa,spaceDim,arr->getPointer(),MED_FULL_INTERLACE,mesh[0]->getNumberOfNodes(),MED_CART,comp,unit);
- delete [] comp;
- delete [] unit;
- delete [] maa;
- delete [] desc;
- MEDfermer(fid);
+ MEDfamilyCr(fid,maa,familyName,0,0,0);
+
+ MEDmeshNodeCoordinateWr(fid,maa,-1,-1,0.,MED_FULL_INTERLACE,mesh[0]->getNumberOfNodes(),arr->getPointer());
+ MEDfileClose(fid);
}
/*!
void MEDLoaderNS::writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool forceFromScratch)
{
std::string meshNameCpp(meshName);
- char *maa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- MEDLoaderBase::safeStrCpy(meshName,MED_TAILLE_NOM,maa,MEDLoader::_TOO_LONG_STR);
+ char *maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ MEDLoaderBase::safeStrCpy(meshName,MED_NAME_SIZE,maa,MEDLoader::_TOO_LONG_STR);
if(meshNameCpp=="")
throw INTERP_KERNEL::Exception("writeUMeshesPartitionDirectly : Invalid meshName : Must be different from \"\" !");
std::vector< DataArrayInt * > corr;
gidsOfFamilies[fid].push_back(gid);
}
fid=0;
- med_idt fid2=MEDouvrir((char *)fileName,MED_LECTURE_ECRITURE);
+ med_idt fid2=MEDfileOpen(fileName,MED_ACC_RDWR);
for(std::set<int>::const_iterator it=familyIds.begin();it!=familyIds.end();it++,fid++)
{
int ngro=gidsOfFamilies[fid].size();
- char *groName=MEDLoaderBase::buildEmptyString(MED_TAILLE_LNOM*ngro);
+ char *groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
for(int i=0;i<ngro;i++)
- MEDLoaderBase::safeStrCpy(meshes[gidsOfFamilies[fid][i]]->getName(),MED_TAILLE_LNOM-1,groName+i*MED_TAILLE_LNOM,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_LNOM-1 to avoid to write '\0' on next compo
+ MEDLoaderBase::safeStrCpy2(meshes[gidsOfFamilies[fid][i]]->getName(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_LNAME_SIZE-1 to avoid to write '\0' on next compo
std::ostringstream oss; oss << "Family_" << *it;
- char *famName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_TAILLE_NOM,famName,MEDLoader::_TOO_LONG_STR);
- MEDfamCr(fid2,maa,famName,*it,0,0,0,0,groName,ngro);
+ char *famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,famName,MEDLoader::_TOO_LONG_STR);
+ MEDfamilyCr(fid2,maa,famName,*it,ngro,groName);
delete [] famName;
delete [] groName;
}
- MEDfermer(fid2);
+ MEDfileClose(fid2);
// end families creation
delete [] maa;
arr2->decrRef();
{
med_int numdt,numo;
med_float dt;
- char *nommaa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_TAILLE_NOM,nommaa,MEDLoader::_TOO_LONG_STR);
+ INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
int nbOfNodes=f->getMesh()->getNumberOfNodes();
const double *pt=f->getArray()->getConstPointer();
- int *profile=new int[nbOfNodes];
+ INTERP_KERNEL::AutoPtr<int> profile=new int[nbOfNodes];
std::ostringstream oss; oss << "Pfln" << f->getName();
- char *profileName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_TAILLE_NOM,profileName,MEDLoader::_TOO_LONG_STR);
- std::transform(thisMeshNodeIds,thisMeshNodeIds+nbOfNodes,profile,std::bind2nd(std::plus<int>(),1));
- MEDprofilEcr(fid,profile,nbOfNodes,profileName);
- delete [] profile;
- MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfNodes,
- (char *)MED_NOGAUSS,MED_ALL,profileName,MED_COMPACT,MED_NOEUD,
- MED_NONE,numdt,(char *)"",dt,numo);
- delete [] profileName;
- delete [] nommaa;
- MEDfermer(fid);
+ INTERP_KERNEL::AutoPtr<char> profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR);
+ std::transform(thisMeshNodeIds,thisMeshNodeIds+nbOfNodes,(int *)profile,std::bind2nd(std::plus<int>(),1));
+ MEDprofileWr(fid,profileName,nbOfNodes,profile);
+ MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE,MED_NONE,MED_COMPACT_PFLMODE,profileName,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfNodes,(const unsigned char*)pt);
+ MEDfileClose(fid);
}
/*!
int number=0;
for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
{
- char *nommaa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_TAILLE_NOM,nommaa,MEDLoader::_TOO_LONG_STR);
- char *profileName=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
+ INTERP_KERNEL::AutoPtr<char> profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++;
- MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_TAILLE_NOM,profileName,MEDLoader::_TOO_LONG_STR);
+ MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR);
const std::vector<int>& ids=(*iter).getCellIdPerType();
int *profile=new int [ids.size()];
std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus<int>(),1));
- MEDprofilEcr(fid,profile,ids.size(),profileName);
+ MEDprofileWr(fid,profileName,ids.size(),profile);
delete [] profile;
- MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,(*iter).getNbOfTuple(),
- (char *)MED_NOGAUSS,MED_ALL,profileName,MED_COMPACT,MED_MAILLE,
- typmai3[(int)(*iter).getType()],numdt,(char *)"",dt,numo);
- delete [] profileName;
- delete [] nommaa;
+ MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,profileName,
+ MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt);
pt+=(*iter).getNbOfTuple()*nbComp;
}
- MEDfermer(fid);
+ MEDfileClose(fid);
}
/*!
*/
med_idt MEDLoaderNS::appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, med_int& numdt, med_int& numo, med_float& dt)
{
- med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE_ECRITURE);
+ med_idt fid=MEDfileOpen(fileName,MED_ACC_RDWR);
int nbComp=f->getNumberOfComponents();
- char *comp=MEDLoaderBase::buildEmptyString(nbComp*MED_TAILLE_PNOM);
- char *unit=MEDLoaderBase::buildEmptyString(nbComp*MED_TAILLE_PNOM);
+ INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
for(int i=0;i<nbComp;i++)
{
std::string info=f->getArray()->getInfoOnComponent(i);
std::string c,u;
MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
- MEDLoaderBase::safeStrCpy(c.c_str(),MED_TAILLE_PNOM-1,comp+i*MED_TAILLE_PNOM,MEDLoader::_TOO_LONG_STR);
- MEDLoaderBase::safeStrCpy(u.c_str(),MED_TAILLE_PNOM-1,unit+i*MED_TAILLE_PNOM,MEDLoader::_TOO_LONG_STR);
- }
- MEDchampCr(fid,(char *)f->getName(),MED_FLOAT64,comp,unit,nbComp);
+ MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);
+ MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);
+ }
+ INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> maaname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ INTERP_KERNEL::AutoPtr<char> fname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ MEDLoaderBase::safeStrCpy(f->getName(),MED_NAME_SIZE,fname,MEDLoader::_TOO_LONG_STR);
+ MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,maaname,MEDLoader::_TOO_LONG_STR);
+ MEDfieldCr(fid,fname,MED_FLOAT64,nbComp,comp,unit,dt_unit,maaname);
ParaMEDMEM::TypeOfTimeDiscretization td=f->getTimeDiscretization();
if(td==ParaMEDMEM::NO_TIME)
{
- numdt=MED_NOPDT; numo=MED_NONOR; dt=0.0;
+ numdt=MED_NO_DT; numo=MED_NO_IT; dt=0.0;
}
else if(td==ParaMEDMEM::ONE_TIME)
{
numdt=(med_int)tmp1; numo=(med_int)tmp2;
dt=(med_float)tmp0;
}
- delete [] comp;
- delete [] unit;
return fid;
}
const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(mesh);
if(!meshC)
throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !");
- bool renum=!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2);
+ bool renum=!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
if(renum)
{
ParaMEDMEM::MEDCouplingFieldDouble *f3=f2->clone(true);
- DataArrayInt *da=meshC->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2);
+ DataArrayInt *da=meshC->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
f3->renumberCells(da->getConstPointer(),false);
da->decrRef();
f=f3;
int nbComp=f->getNumberOfComponents();
med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
const double *pt=f->getArray()->getConstPointer();
- char *nommaa=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
- MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_TAILLE_NOM,nommaa,MEDLoader::_TOO_LONG_STR);
+ INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
switch(f->getTypeOfField())
{
case ParaMEDMEM::ON_CELLS:
prepareCellFieldDoubleForWriting(f,0,split);
for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
{
- MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,(*iter).getNbOfTuple(),
- (char *)MED_NOGAUSS,MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_MAILLE,
- typmai3[(int)(*iter).getType()],numdt,(char *)"",dt,numo);
+ MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,
+ MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt);
pt+=(*iter).getNbOfTuple()*nbComp;
}
break;
case ParaMEDMEM::ON_NODES:
{
int nbOfTuples=f->getArray()->getNumberOfTuples();
- MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfTuples,(char *)MED_NOGAUSS,
- MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_NOEUD,MED_NONE,numdt,(char *)"",dt,numo);
+ MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE,MED_NONE,MED_COMPACT_PFLMODE,
+ MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfTuples,(const unsigned char*)pt);
break;
}
case ParaMEDMEM::ON_GAUSS_PT:
int idGp=0;
for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
{
- char *nomGauss=MEDLoaderBase::buildEmptyString(MED_TAILLE_NOM);
+ INTERP_KERNEL::AutoPtr<char> nomGauss=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
std::ostringstream oss; oss << "GP_" << f->getName() << idGp++;
- MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_TAILLE_NOM,nomGauss,MEDLoader::_TOO_LONG_STR);
+ MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,nomGauss,MEDLoader::_TOO_LONG_STR);
int id=f->getGaussLocalizationIdOfOneType((*iter).getType());
const MEDCouplingGaussLocalization& gl=f->getGaussLocalization(id);
- MEDgaussEcr(fid,typmai3[(int)(*iter).getType()],(med_float*)&gl.getRefCoords()[0],MED_FULL_INTERLACE,gl.getNumberOfGaussPt(),
- (med_float*)&gl.getGaussCoords()[0],
- (med_float*)&gl.getWeights()[0],nomGauss);
- int nbOfValues=gl.getNumberOfGaussPt()*f->getMesh()->getNumberOfCellsWithType((*iter).getType());
- MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfValues,
- nomGauss,MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_MAILLE,
- typmai3[(int)(*iter).getType()],numdt,(char *)"",dt,numo);
+ MEDlocalizationWr(fid,nomGauss,typmai3[(int)(*iter).getType()],mesh->getMeshDimension(),&gl.getRefCoords()[0],MED_FULL_INTERLACE,
+ gl.getNumberOfGaussPt(),&gl.getGaussCoords()[0],&gl.getWeights()[0],MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT);
+ int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType());
+ int nbOfValues=gl.getNumberOfGaussPt()*nbOfEntity;
+ INTERP_KERNEL::AutoPtr<char> fieldname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
+ MEDLoaderBase::safeStrCpy(f->getName(),MED_NAME_SIZE,fieldname,MEDLoader::_TOO_LONG_STR);
+ MEDfieldValueWithProfileWr(fid,fieldname,numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,
+ MED_ALLENTITIES_PROFILE,nomGauss,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt);
pt+=nbOfValues*nbComp;
- delete [] nomGauss;
}
break;
}
for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
{
int nbPtPerCell=(int)INTERP_KERNEL::CellModel::getCellModel((*iter).getType()).getNumberOfNodes();
- int nbOfValues=nbPtPerCell*f->getMesh()->getNumberOfCellsWithType((*iter).getType());
- MEDchampEcr(fid,nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfValues,
- (char *)MED_GAUSS_ELNO,MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_MAILLE,
- typmai3[(int)(*iter).getType()],numdt,(char *)"",dt,numo);
+ int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType());
+ int nbOfValues=nbPtPerCell*nbOfEntity;
+ MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE_ELEMENT,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,
+ MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt);
pt+=nbOfValues*nbComp;
}
break;
default:
throw INTERP_KERNEL::Exception("Not managed this type of FIELD !");
}
- delete [] nommaa;
- MEDfermer(fid);
+ MEDfileClose(fid);
if(renum)
((ParaMEDMEM::MEDCouplingFieldDouble *)f)->decrRef();
}
const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(mesh);
if(!meshC)
throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !");
- if(!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2))
+ if(!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
throw INTERP_KERNEL::Exception("Unstructuded mesh has not consecutive cell types !");
const int *connI=meshC->getNodalConnectivityIndex()->getConstPointer();
const int *conn=meshC->getNodalConnectivity()->getConstPointer();
if(isRenumbering)
{
ParaMEDMEM::MEDCouplingFieldDouble *f2=f->clone(true);
- DataArrayInt *da=mesh->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_NBR_GEOMETRIE_MAILLE+2);
+ DataArrayInt *da=mesh->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
f2->renumberCells(da->getConstPointer(),false);
da->decrRef();
appendFieldDirectly(fileName,f2);
std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
}
- std::string fieldName(f->getName());
- if(fieldName.empty())
- throw INTERP_KERNEL::Exception("Trying to write a field with no name ! MED file format needs a not empty field name !");
MEDLoaderNS::appendFieldDirectly(fileName,f);
}
strcpy(dest,src);
}
+/*!
+ * This method is equivalent to MEDLoaderBase::safeStrCpy except that here no '\0' car is put.
+ * This method should be used for multi string in one string.
+ */
+void MEDLoaderBase::safeStrCpy2(const char *src, int maxLgth, char *dest, int behaviour) throw(INTERP_KERNEL::Exception)
+{
+ if((int)strlen(src)>maxLgth)
+ {
+ if(behaviour==0 || behaviour>1)
+ {
+ std::ostringstream oss; oss << "A string : \"" << src << "\" has been detected to be too long for MED File ( > " << maxLgth << ") !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ else if(behaviour==1)
+ {
+ std::string s=zipString(src,maxLgth);
+ std::cerr << "A string : \"" << src << "\" has been detected to be too long for MED File ( > " << maxLgth << ") : ";
+ std::cerr << "zipping to : " << s << "\n";
+ strcpy(dest,s.c_str());
+ return ;
+ }
+ }
+ int n=strlen(src);
+ strncpy(dest,src,n);
+}
+
std::string MEDLoaderBase::buildStringFromFortran(const char *expr, int lgth)
{
std::string ret(expr,lgth);
static void splitIntoNameAndUnit(const std::string& s, std::string& name, std::string& unit);
static void strip(std::string& s);
static void safeStrCpy(const char *src, int maxLgth, char *dest, int behaviour) throw(INTERP_KERNEL::Exception);
+ static void safeStrCpy2(const char *src, int maxLgth, char *dest, int behaviour) throw(INTERP_KERNEL::Exception);
static std::string buildStringFromFortran(const char *expr, int lgth);
static void zipEqualConsChar(std::string& s, int minConsSmChar);
static std::string zipString(const char *src, int sizeToRespect);
%{
#include "MEDLoader.hxx"
#include "MEDFileMesh.hxx"
+#include "MEDFileField.hxx"
#include "MEDLoaderTypemaps.i"
using namespace ParaMEDMEM;
%newobject MEDLoader::ReadFieldNode;
%newobject MEDLoader::ReadFieldGauss;
%newobject MEDLoader::ReadFieldGaussNE;
+%newobject ParaMEDMEM::MEDFileMesh::New;
+%newobject ParaMEDMEM::MEDFileMesh::getGenMeshAtLevel;
+%newobject ParaMEDMEM::MEDFileMesh::getGroupArr;
+%newobject ParaMEDMEM::MEDFileMesh::getGroupsArr;
+%newobject ParaMEDMEM::MEDFileMesh::getFamilyArr;
+%newobject ParaMEDMEM::MEDFileMesh::getFamiliesArr;
+%newobject ParaMEDMEM::MEDFileMesh::getNodeGroupArr;
+%newobject ParaMEDMEM::MEDFileMesh::getNodeGroupsArr;
+%newobject ParaMEDMEM::MEDFileMesh::getNodeFamilyArr;
+%newobject ParaMEDMEM::MEDFileMesh::getNodeFamiliesArr;
%newobject ParaMEDMEM::MEDFileUMesh::New;
%newobject ParaMEDMEM::MEDFileUMesh::getCoords;
%newobject ParaMEDMEM::MEDFileUMesh::getGroup;
%newobject ParaMEDMEM::MEDFileUMesh::getGroups;
%newobject ParaMEDMEM::MEDFileUMesh::getFamily;
%newobject ParaMEDMEM::MEDFileUMesh::getFamilies;
-%newobject ParaMEDMEM::MEDFileUMesh::getGroupArr;
-%newobject ParaMEDMEM::MEDFileUMesh::getGroupsArr;
-%newobject ParaMEDMEM::MEDFileUMesh::getFamilyArr;
-%newobject ParaMEDMEM::MEDFileUMesh::getFamiliesArr;
-%newobject ParaMEDMEM::MEDFileUMesh::getNodeGroupArr;
-%newobject ParaMEDMEM::MEDFileUMesh::getNodeGroupsArr;
-%newobject ParaMEDMEM::MEDFileUMesh::getNodeFamilyArr;
-%newobject ParaMEDMEM::MEDFileUMesh::getNodeFamiliesArr;
%newobject ParaMEDMEM::MEDFileUMesh::getMeshAtLevel;
%newobject ParaMEDMEM::MEDFileUMesh::getLevel0Mesh;
%newobject ParaMEDMEM::MEDFileUMesh::getLevelM1Mesh;
%newobject ParaMEDMEM::MEDFileUMesh::getLevelM2Mesh;
%newobject ParaMEDMEM::MEDFileUMesh::getLevelM3Mesh;
+%newobject ParaMEDMEM::MEDFileCMesh::New;
+
+%newobject ParaMEDMEM::MEDFileFields::New;
+%newobject ParaMEDMEM::MEDFileFieldMultiTS::New;
+%newobject ParaMEDMEM::MEDFileField1TS::New;
class MEDLoader
{
static void WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception);
};
-%include "MEDFileMesh.hxx"
-
-%extend ParaMEDMEM::MEDFileUMesh
+namespace ParaMEDMEM
{
- void setGroupsAtLevel(int meshDimRelToMaxExt, PyObject *li, bool renum=false) throw(INTERP_KERNEL::Exception)
+ class MEDFileMesh : public RefCountObject
+ {
+ public:
+ static MEDFileMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ static MEDFileMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1);
+ virtual void clearNonDiscrAttributes() const;
+ void setName(const char *name);
+ const char *getName();
+ void setUnivName(const char *name);
+ const char *getUnivName() const;
+ void setDescription(const char *name);
+ const char *getDescription() const;
+ void setOrder(int order);
+ int getOrder() const;
+ void setIteration(int it);
+ int getIteration();
+ void setTimeValue(double time);
+ void setTime(double time, int dt, int it);
+ double getTimeValue() const;
+ void setTimeUnit(const char *unit);
+ const char *getTimeUnit() const;
+ void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
+ int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
+ //
+ bool existsFamily(int famId) const;
+ bool existsFamily(const char *familyName) const;
+ void setFamilyId(const char *familyName, int id);
+ void addFamily(const char *familyName, int id) throw(INTERP_KERNEL::Exception);
+ void addGrpOnFamily(const char *grpName, const char *famName) throw(INTERP_KERNEL::Exception);
+ void copyFamGrpMapsFrom(const MEDFileMesh& other);
+ const std::map<std::string,int>& getFamilyInfo() const;
+ const std::map<std::string, std::vector<std::string> >& getGroupInfo() const;
+ std::vector<std::string> getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception);
+ std::vector<std::string> getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception);
+ std::vector<std::string> getGroupsNames() const;
+ std::vector<std::string> getFamiliesNames() const;
+ void removeGroup(const char *name) throw(INTERP_KERNEL::Exception);
+ void removeFamily(const char *name) throw(INTERP_KERNEL::Exception);
+ void changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception);
+ void changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception);
+ void setFamilyInfo(const std::map<std::string,int>& info);
+ void setGroupInfo(const std::map<std::string, std::vector<std::string> >&info);
+ int getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception);
+ int getMaxFamilyId() const throw(INTERP_KERNEL::Exception);
+ std::vector<int> getFamiliesIds(const std::vector<std::string>& famNames) const throw(INTERP_KERNEL::Exception);
+ std::string getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception);
+ //
+ virtual MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception);
+ virtual void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception);
+ virtual void setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getNodeGroupArr(const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getNodeGroupsArr(const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ virtual DataArrayInt *getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ %extend
+ {
+ PyObject *getTime()
+ {
+ int tmp1,tmp2;
+ double tmp0=self->getTime(tmp1,tmp2);
+ PyObject *res = PyList_New(3);
+ PyList_SetItem(res,0,SWIG_From_double(tmp0));
+ PyList_SetItem(res,1,SWIG_From_int(tmp1));
+ PyList_SetItem(res,2,SWIG_From_int(tmp2));
+ return res;
+ }
+
+ virtual PyObject *isEqual(const MEDFileMesh *other, double eps) const
+ {
+ std::string what;
+ bool ret0=self->isEqual(other,eps,what);
+ PyObject *res=PyList_New(2);
+ PyObject *ret0Py=ret0?Py_True:Py_False;
+ Py_XINCREF(ret0Py);
+ PyList_SetItem(res,0,ret0Py);
+ PyList_SetItem(res,1,PyString_FromString(what.c_str()));
+ return res;
+ }
+
+ PyObject *areFamsEqual(const MEDFileMesh *other) const
+ {
+ std::string what;
+ bool ret0=self->areFamsEqual(other,what);
+ PyObject *res=PyList_New(2);
+ PyObject *ret0Py=ret0?Py_True:Py_False;
+ Py_XINCREF(ret0Py);
+ PyList_SetItem(res,0,ret0Py);
+ PyList_SetItem(res,1,PyString_FromString(what.c_str()));
+ return res;
+ }
+
+ PyObject *areGrpsEqual(const MEDFileMesh *other) const
+ {
+ std::string what;
+ bool ret0=self->areGrpsEqual(other,what);
+ PyObject *res=PyList_New(2);
+ PyObject *ret0Py=ret0?Py_True:Py_False;
+ Py_XINCREF(ret0Py);
+ PyList_SetItem(res,0,ret0Py);
+ PyList_SetItem(res,1,PyString_FromString(what.c_str()));
+ return res;
+ }
+
+ PyObject *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+ {
+ const DataArrayInt *tmp=self->getFamilyFieldAtLevel(meshDimRelToMaxExt);
+ if(tmp)
+ tmp->incrRef();
+ return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 );
+ }
+
+ PyObject *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+ {
+ const DataArrayInt *tmp=self->getNumberFieldAtLevel(meshDimRelToMaxExt);
+ if(tmp)
+ tmp->incrRef();
+ return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 );
+ }
+ }
+ };
+
+ class MEDFileUMesh : public MEDFileMesh
+ {
+ public:
+ static MEDFileUMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception);
+ static MEDFileUMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ static MEDFileUMesh *New();
+ ~MEDFileUMesh();
+ //
+ int getMeshDimension() const;
+ std::vector<int> getNonEmptyLevels() const;
+ std::vector<int> getNonEmptyLevelsExt() const;
+ DataArrayDouble *getCoords() const;
+ MEDCouplingUMesh *getGroup(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getFamily(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getNodeGroupArr(const char *grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getNodeGroupsArr(const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getNodeFamilyArr(const char *fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ DataArrayInt *getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getMeshAtLevel(int meshDimRelToMaxExt, bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getLevel0Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getLevelM1Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getLevelM2Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
+ MEDCouplingUMesh *getLevelM3Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
+ //
+ void setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception);
+ void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
+ void eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception);
+ void setFamilyField(DataArrayInt *arr, const std::vector< std::vector< int > > &userfids, const std::vector<std::string>& grpNames, bool renum=false) throw(INTERP_KERNEL::Exception);
+ void addNodeGroup(const std::string& name, const std::vector<int>& ids) throw(INTERP_KERNEL::Exception);
+ void setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception);
+ void setMeshAtLevelOld(int meshDimRelToMax, MEDCouplingUMesh *m) throw(INTERP_KERNEL::Exception);
+ void setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception);
+ void setGroupsFromScratch(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception);
+ void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum) throw(INTERP_KERNEL::Exception);
+ void optimizeFamilies() throw(INTERP_KERNEL::Exception);
+ %extend
+ {
+ PyObject *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+ {
+ const DataArrayInt *tmp=self->getRevNumberFieldAtLevel(meshDimRelToMaxExt);
+ if(tmp)
+ tmp->incrRef();
+ return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 );
+ }
+
+ void setGroupsAtLevel(int meshDimRelToMaxExt, PyObject *li, bool renum=false) throw(INTERP_KERNEL::Exception)
+ {
+ std::vector<const DataArrayInt *> grps;
+ convertPyObjToVecDataArrayIntCst(li,grps);
+ self->setGroupsAtLevel(meshDimRelToMaxExt,grps,renum);
+ }
+ }
+ };
+
+ class MEDFileCMesh : public MEDFileMesh
+ {
+ public:
+ static MEDFileCMesh *New();
+ static MEDFileCMesh *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ static MEDFileCMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception);
+ void setMesh(MEDCouplingCMesh *m);
+ %extend
+ {
+ PyObject *getMesh() const
+ {
+ const MEDCouplingCMesh *tmp=self->getMesh();
+ if(tmp)
+ tmp->incrRef();
+ return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh, SWIG_POINTER_OWN | 0 );
+ }
+ }
+ };
+
+ class MEDFieldFieldGlobs
+ {
+ public:
+ std::vector<std::string> getPfls() const;
+ std::vector<std::string> getLocs() const;
+ };
+
+ class MEDFileField1TSWithoutDAS : public RefCountObject
+ {
+ public:
+ int getIteration() const;
+ int getOrder() const;
+ std::string getName();
+ std::string getMeshName();
+ int getNumberOfComponents() const;
+ const std::vector<std::string>& getInfos() const;
+ std::vector<std::string> getPflsReallyUsed() const;
+ std::vector<std::string> getLocsReallyUsed() const;
+ };
+
+ class MEDFileField1TS : public MEDFileField1TSWithoutDAS, public MEDFieldFieldGlobs
+ {
+ public:
+ static MEDFileField1TS *New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception);
+ };
+
+ class MEDFileFieldMultiTSWithoutDAS
+ {
+ public:
+ int getNumberOfTS() const;
+ };
+
+ class MEDFileFieldMultiTS : public MEDFileFieldMultiTSWithoutDAS, public MEDFieldFieldGlobs
+ {
+ public:
+ static MEDFileFieldMultiTS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception);
+ };
+
+ class MEDFileFields : public RefCountObject, public MEDFieldFieldGlobs
{
- std::vector<const DataArrayInt *> grps;
- convertPyObjToVecDataArrayIntCst(li,grps);
- self->setGroupsAtLevel(meshDimRelToMaxExt,grps,renum);
- }
+ public:
+ static MEDFileFields *New(const char *fileName) throw(INTERP_KERNEL::Exception);
+ int getNumberOfFields() const;
+ std::vector<std::string> getPfls() const;
+ std::vector<std::string> getLocs() const;
+ };
}
VAL2=-1111111111111.;
name1="AField";
name3="AMesh1";
- name2="AMesh2";
f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
f1.getMesh().setName(name3);
f1.setName(name1);
f1.setTime(10.14,18,19);
f1.getArray().setIJ(0,0,VAL2);
MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
- f1.getMesh().setName(name2);
+ f1.getMesh().setName(name3);
f1.setTime(10.55,28,29);
f1.getArray().setIJ(0,0,3*VAL1);
- MEDLoader.MEDLoader.WriteField(fileName,f1,False);
+ MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
vec=MEDLoader.MEDLoader.GetMeshNamesOnField(fileName,name1);
- self.assertEqual(2,len(vec));
- self.assertTrue(vec[0]==name3);
- self.assertTrue(vec[1]==name2);
f1.setTime(10.66,38,39);
f1.getArray().setIJ(0,0,3*VAL2);
MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
#ON NODES
f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
f1.setName(name1);
- f1.getMesh().setName(name2);
+ f1.getMesh().setName(name3);
f1.setTime(110.,8,9);
MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
f1.setTime(110.,108,109);
MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
#
it1=MEDLoader.MEDLoader.GetCellFieldIterations(fileName,name3,name1);
- self.assertEqual(2,len(it1));
+ self.assertEqual(5,len(it1));
self.assertEqual(8,it1[0][0]); self.assertEqual(9,it1[0][1]);
self.assertEqual(18,it1[1][0]); self.assertEqual(19,it1[1][1]);
- it2=MEDLoader.MEDLoader.GetCellFieldIterations(fileName,name2,name1);
- self.assertEqual(3,len(it2));
- self.assertEqual(28,it2[0][0]); self.assertEqual(29,it2[0][1]);
- self.assertEqual(38,it2[1][0]); self.assertEqual(39,it2[1][1]);
- self.assertEqual(48,it2[2][0]); self.assertEqual(49,it2[2][1]);
- it3=MEDLoader.MEDLoader.GetNodeFieldIterations(fileName,name2,name1);
+ self.assertEqual(28,it1[2][0]); self.assertEqual(29,it1[2][1]);
+ self.assertEqual(38,it1[3][0]); self.assertEqual(39,it1[3][1]);
+ self.assertEqual(48,it1[4][0]); self.assertEqual(49,it1[4][1]);
+ it3=MEDLoader.MEDLoader.GetNodeFieldIterations(fileName,name3,name1);
self.assertEqual(3,len(it3));
self.assertEqual(8,it3[0][0]); self.assertEqual(9,it3[0][1]);
self.assertEqual(108,it3[1][0]); self.assertEqual(109,it3[1][1]);
self.assertEqual(208,it3[2][0]); self.assertEqual(209,it3[2][1]);
- it4=MEDLoader.MEDLoader.GetNodeFieldIterations(fileName,name3,name1);
- self.assertTrue(len(it4)==0);
#
#
f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,8,9);
self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,0),13);
f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,18,19);
self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,0),13);
- f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name2,0,name1,28,29);
+ f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,28,29);
self.assertAlmostEqual(3*VAL1,f1.getArray().getIJ(0,0),13);
- f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name2,0,name1,38,39);
+ f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,38,39);
self.assertAlmostEqual(3*VAL2,f1.getArray().getIJ(0,0),13);
- f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name2,0,name1,48,49);
+ f1=MEDLoader.MEDLoader.ReadFieldCell(fileName,name3,0,name1,48,49);
self.assertAlmostEqual(4*VAL2,f1.getArray().getIJ(0,0),13);
#
- f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name2,0,name1,8,9);
+ f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name3,0,name1,8,9);
self.assertAlmostEqual(71.,f1.getArray().getIJ(0,3),13);
- f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name2,0,name1,108,109);
+ f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name3,0,name1,108,109);
self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,3),13);
- f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name2,0,name1,208,209);
+ f1=MEDLoader.MEDLoader.ReadFieldNode(fileName,name3,0,name1,208,209);
self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,3),13);
pass
array.setValues(arr2,12,2)
array.setInfoOnComponent(0,"plkj [mm]");
array.setInfoOnComponent(1,"pqqqss [mm]");
- f2.setTime(3.17,2,7);
+ f2.setTime(3.14,2,7);
f2.checkCoherency();
#
MEDLoader.MEDLoader.WriteField(fileName,f1,True);
VAL2=-1111111111111.;
name1="AField";
name3="AMesh1";
- name2="AMesh2";
f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
f1.getMesh().setName(name3);
f1.setName(name1);
f1.setTime(10.14,18,19);
f1.getArray().setIJ(0,0,VAL2);
MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
- f1.getMesh().setName(name2);
+ f1.getMesh().setName(name3);
f1.setTime(10.55,28,29);
f1.getArray().setIJ(0,0,3*VAL1);
- MEDLoader.WriteFieldDep(fileName,f1,False);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
f1.setTime(10.66,38,39);
f1.getArray().setIJ(0,0,3*VAL2);
MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
#ON NODES
f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
f1.setName(name1);
- f1.getMesh().setName(name2);
+ f1.getMesh().setName(name3);
f1.setTime(110.,8,9);
MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
f1.setTime(110.,108,109);
MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
#
it1=MEDLoader.GetCellFieldIterations(fileName,name3,name1);
- self.assertEqual(2,len(it1));
+ self.assertEqual(5,len(it1));
self.assertEqual(8,it1[0][0]); self.assertEqual(9,it1[0][1]);
self.assertEqual(18,it1[1][0]); self.assertEqual(19,it1[1][1]);
- it2=MEDLoader.GetCellFieldIterations(fileName,name2,name1);
- self.assertEqual(3,len(it2));
- self.assertEqual(28,it2[0][0]); self.assertEqual(29,it2[0][1]);
- self.assertEqual(38,it2[1][0]); self.assertEqual(39,it2[1][1]);
- self.assertEqual(48,it2[2][0]); self.assertEqual(49,it2[2][1]);
- it3=MEDLoader.GetNodeFieldIterations(fileName,name2,name1);
+ self.assertEqual(28,it1[2][0]); self.assertEqual(29,it1[2][1]);
+ self.assertEqual(38,it1[3][0]); self.assertEqual(39,it1[3][1]);
+ self.assertEqual(48,it1[4][0]); self.assertEqual(49,it1[4][1]);
+ it3=MEDLoader.GetNodeFieldIterations(fileName,name3,name1);
self.assertEqual(3,len(it3));
self.assertEqual(8,it3[0][0]); self.assertEqual(9,it3[0][1]);
self.assertEqual(108,it3[1][0]); self.assertEqual(109,it3[1][1]);
self.assertEqual(208,it3[2][0]); self.assertEqual(209,it3[2][1]);
- it4=MEDLoader.GetNodeFieldIterations(fileName,name3,name1);
- self.assertTrue(len(it4)==0);
#
#
f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,8,9);
self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,0),13);
f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,18,19);
self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,0),13);
- f1=MEDLoader.ReadFieldCell(fileName,name2,0,name1,28,29);
+ f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,28,29);
self.assertAlmostEqual(3*VAL1,f1.getArray().getIJ(0,0),13);
- f1=MEDLoader.ReadFieldCell(fileName,name2,0,name1,38,39);
+ f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,38,39);
self.assertAlmostEqual(3*VAL2,f1.getArray().getIJ(0,0),13);
- f1=MEDLoader.ReadFieldCell(fileName,name2,0,name1,48,49);
+ f1=MEDLoader.ReadFieldCell(fileName,name3,0,name1,48,49);
self.assertAlmostEqual(4*VAL2,f1.getArray().getIJ(0,0),13);
#
- f1=MEDLoader.ReadFieldNode(fileName,name2,0,name1,8,9);
+ f1=MEDLoader.ReadFieldNode(fileName,name3,0,name1,8,9);
self.assertAlmostEqual(71.,f1.getArray().getIJ(0,3),13);
- f1=MEDLoader.ReadFieldNode(fileName,name2,0,name1,108,109);
+ f1=MEDLoader.ReadFieldNode(fileName,name3,0,name1,108,109);
self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,3),13);
- f1=MEDLoader.ReadFieldNode(fileName,name2,0,name1,208,209);
+ f1=MEDLoader.ReadFieldNode(fileName,name3,0,name1,208,209);
self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,3),13);
pass
def testMEDMesh1(self):
fileName="Pyfile18.med"
mname="ExampleOfMultiDimW"
- medmesh=MEDFileUMesh.New(fileName,mname)
+ medmesh=MEDFileMesh.New(fileName,mname)
self.assertEqual((0,-1),medmesh.getNonEmptyLevels())
m1_0=medmesh.getLevel0Mesh(True)
m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0)
self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"],True).getValues());
self.assertEqual([19,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"],True).getValues());
famn=medmesh.getFamilyNameGivenId(0)
- self.assertEqual(range(60),medmesh.getNodeFamilyArr(famn,True).getValues());
+ self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,True);
#without renum
self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2",False).getValues());
self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_2",False).getValues());
self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"],False).getValues());
self.assertEqual([0,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3","mesh4"],False).getValues());
- self.assertEqual(range(60),medmesh.getNodeFamilyArr(famn,False).getValues());
+ self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,False);
pass
# this tests emulates MEDMEM ( Except that it works ! ) The permutation are NOT taken into account
coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ];
targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
c.setValues(coords,9,2)
+ c.setInfoOnComponent(0,"abcdef [km]")
+ c.setInfoOnComponent(1,"ghij [MW]")
m=MEDCouplingUMesh.New();
m.setMeshDimension(2);
m.allocateCells(5);
mm.setCoords(c)
renumNode=DataArrayInt.New()
renumNode.setValues([10,11,12,13,14,15,16,17,18],9,1)
- mm.setRenumArr(1,renumNode)
+ mm.setRenumFieldArr(1,renumNode)
mm.setMeshAtLevel(-1,m1);
mm.setMeshAtLevel(0,m);
mm.setMeshAtLevel(-2,m2);
self.assertTrue(g2_1.isEqual(t));
#
mm.write(outFileName,2);
+ mm2=MEDFileMesh.New(outFileName)
+ res=mm.isEqual(mm2,1e-12)
+ self.assertTrue(res[0])
+ pass
+
+ #testing persistence of retrieved arrays
+ def testMEDMesh5(self):
+ fileName="Pyfile18.med"
+ mname="ExampleOfMultiDimW"
+ medmesh=MEDFileUMesh.New(fileName,mname)
+ m1_0=medmesh.getLevel0Mesh(True)
+ da1=medmesh.getFamilyFieldAtLevel(0)
+ del medmesh
+ self.assertEqual(20,m1_0.getNumberOfCells())
+ self.assertEqual(20,da1.getNumberOfTuples())
+ pass
+
+ def testMEDMesh6(self):
+ outFileName="MEDFileMesh5.med"
+ m=MEDFileCMesh.New()
+ m.setTime(2.3,-1,-1)
+ m1=MEDCouplingCMesh.New();
+ da=DataArrayDouble.New()
+ da.setValues([0.,1.,2.],3,1)
+ da.setInfoOnComponent(0,"XX [mm]")
+ m1.setCoordsAt(0,da)
+ da=DataArrayDouble.New()
+ da.setValues([0.,1.2],2,1)
+ da.setInfoOnComponent(0,"YY [km]")
+ m1.setCoordsAt(1,da)
+ da=DataArrayDouble.New()
+ da.setValues([0.,1.3],2,1)
+ da.setInfoOnComponent(0,"ZZ [um]")
+ m1.setCoordsAt(2,da)
+ m.setMesh(m1)
+ m.setName("myFirstCartMesh")
+ m.setDescription("mmmmpppppppp")
+ m.setTimeValue(2.3)
+ m.setTimeUnit("ms")
+ da=DataArrayInt.New()
+ da.setValues([0,0,1,0,1,2,4,3,0,1,2,2],12,1)
+ m.setFamilyFieldArr(1,da)
+ m.setFamilyId("family1",1)
+ da=m.getFamilyArr(1,"family1")
+ expected1=[2,4,9]
+ self.assertEqual(expected1,da.getValues())
+ m.write(outFileName,2);
+ mm=MEDFileMesh.New(outFileName)
+ self.assertTrue(m.isEqual(mm,1e-12)[0])
+ self.assertEqual(expected1,mm.getFamilyArr(1,"family1").getValues())
+ m2=mm.getMesh()
+ tt=m.getTime()
+ m1.setTime(tt[0],tt[1],tt[2])
+ m1.setName(m.getName())
+ m1.setTimeUnit(m.getTimeUnit())
+ m1.setDescription(m.getDescription())
+ self.assertTrue(m2.isEqual(m1,1e-12));
pass
pass
static const double VAL2=-1111111111111.;
const char name1[]="AField";
const char name3[]="AMesh1";
- const char name2[]="AMesh2";
MEDCouplingFieldDouble *f1=buildVecFieldOnCells_1();
((MEDCouplingMesh *)f1->getMesh())->setName(name3);
f1->setName(name1);
f1->setTime(10.14,18,19);
tmp[0]=VAL2;
MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
- ((MEDCouplingMesh *)f1->getMesh())->setName(name2);
f1->setTime(10.55,28,29);
tmp[0]=3*VAL1;
- MEDLoader::WriteField(fileName,f1,false);
- std::vector<std::string> vec=MEDLoader::GetMeshNamesOnField(fileName,name1);
- CPPUNIT_ASSERT_EQUAL(2,(int)vec.size());
- CPPUNIT_ASSERT(vec[0]==name3);
- CPPUNIT_ASSERT(vec[1]==name2);
+ MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
f1->setTime(10.66,38,39);
tmp[0]=3*VAL2;
MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
f1->decrRef();
f1=buildVecFieldOnNodes_1();
f1->setName(name1);
- ((MEDCouplingMesh *)f1->getMesh())->setName(name2);
+ ((MEDCouplingMesh *)f1->getMesh())->setName(name3);
f1->setTime(110.,8,9);
MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
f1->setTime(110.,108,109);
MEDLoader::WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
//
std::vector< std::pair<int,int> > it1=MEDLoader::GetCellFieldIterations(fileName,name3,name1);
- CPPUNIT_ASSERT_EQUAL(2,(int)it1.size());
+ CPPUNIT_ASSERT_EQUAL(5,(int)it1.size());
CPPUNIT_ASSERT_EQUAL(8,it1[0].first); CPPUNIT_ASSERT_EQUAL(9,it1[0].second);
CPPUNIT_ASSERT_EQUAL(18,it1[1].first); CPPUNIT_ASSERT_EQUAL(19,it1[1].second);
- std::vector< std::pair<int,int> > it2=MEDLoader::GetCellFieldIterations(fileName,name2,name1);
- CPPUNIT_ASSERT_EQUAL(3,(int)it2.size());
- CPPUNIT_ASSERT_EQUAL(28,it2[0].first); CPPUNIT_ASSERT_EQUAL(29,it2[0].second);
- CPPUNIT_ASSERT_EQUAL(38,it2[1].first); CPPUNIT_ASSERT_EQUAL(39,it2[1].second);
- CPPUNIT_ASSERT_EQUAL(48,it2[2].first); CPPUNIT_ASSERT_EQUAL(49,it2[2].second);
- std::vector< std::pair<int,int> > it3=MEDLoader::GetNodeFieldIterations(fileName,name2,name1);
+ CPPUNIT_ASSERT_EQUAL(28,it1[2].first); CPPUNIT_ASSERT_EQUAL(29,it1[2].second);
+ CPPUNIT_ASSERT_EQUAL(38,it1[3].first); CPPUNIT_ASSERT_EQUAL(39,it1[3].second);
+ CPPUNIT_ASSERT_EQUAL(48,it1[4].first); CPPUNIT_ASSERT_EQUAL(49,it1[4].second);
+ std::vector< std::pair<int,int> > it3=MEDLoader::GetNodeFieldIterations(fileName,name3,name1);
CPPUNIT_ASSERT_EQUAL(3,(int)it3.size());
CPPUNIT_ASSERT_EQUAL(8,it3[0].first); CPPUNIT_ASSERT_EQUAL(9,it3[0].second);
CPPUNIT_ASSERT_EQUAL(108,it3[1].first); CPPUNIT_ASSERT_EQUAL(109,it3[1].second);
CPPUNIT_ASSERT_EQUAL(208,it3[2].first); CPPUNIT_ASSERT_EQUAL(209,it3[2].second);
- std::vector< std::pair<int,int> > it4=MEDLoader::GetNodeFieldIterations(fileName,name3,name1);
- CPPUNIT_ASSERT(it4.empty());
//
f1->decrRef();
//
f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,18,19);
CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[0],1e-13);
f1->decrRef();
- f1=MEDLoader::ReadFieldCell(fileName,name2,0,name1,28,29);
+ f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,28,29);
CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL1,f1->getArray()->getConstPointer()[0],1e-13);
f1->decrRef();
- f1=MEDLoader::ReadFieldCell(fileName,name2,0,name1,38,39);
+ f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,38,39);
CPPUNIT_ASSERT_DOUBLES_EQUAL(3*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
f1->decrRef();
- f1=MEDLoader::ReadFieldCell(fileName,name2,0,name1,48,49);
+ f1=MEDLoader::ReadFieldCell(fileName,name3,0,name1,48,49);
CPPUNIT_ASSERT_DOUBLES_EQUAL(4*VAL2,f1->getArray()->getConstPointer()[0],1e-13);
f1->decrRef();
//
- f1=MEDLoader::ReadFieldNode(fileName,name2,0,name1,8,9);
+ f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,8,9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(71.,f1->getArray()->getConstPointer()[3],1e-13);
f1->decrRef();
- f1=MEDLoader::ReadFieldNode(fileName,name2,0,name1,108,109);
+ f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,108,109);
CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL1,f1->getArray()->getConstPointer()[3],1e-13);
f1->decrRef();
- f1=MEDLoader::ReadFieldNode(fileName,name2,0,name1,208,209);
+ f1=MEDLoader::ReadFieldNode(fileName,name3,0,name1,208,209);
CPPUNIT_ASSERT_DOUBLES_EQUAL(VAL2,f1->getArray()->getConstPointer()[3],1e-13);
f1->decrRef();
}
1060.,1160.,1070.,1170.,1080.,1180.,1090.,1190.,1091.,1191.,1092.,1192.
};
std::copy(arr2,arr2+24,tmp);
- f2->setTime(3.17,2,7);
+ f2->setTime(3.14,2,7);
f2->checkCoherency();
//
MEDLoader::WriteField(fileName,f1,true);