From: ageay Date: Thu, 25 Nov 2010 15:49:02 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=189a90dc5fbab90edc4b1a519b8c7ff0ee76f03b;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDLoader/MEDFileBasis.cxx b/src/MEDLoader/MEDFileBasis.cxx new file mode 100644 index 000000000..0fedbd2c0 --- /dev/null +++ b/src/MEDLoader/MEDFileBasis.cxx @@ -0,0 +1,48 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileBasis.hxx" + +#include + +using namespace ParaMEDMEM; + +MEDFileString::MEDFileString(int maxLgth):_max_lgth(maxLgth),_content(new char[maxLgth+1]) +{ + std::fill(_content,_content+maxLgth+1,'\0'); +} + +MEDFileString::~MEDFileString() +{ + delete [] _content; +} + +void MEDFileString::set(const char *s) throw(INTERP_KERNEL::Exception) +{ + if((int)strlen(s)>_max_lgth) + throw INTERP_KERNEL::Exception("Name is too long to be stored in MEDfile !"); + std::fill(_content,_content+_max_lgth+1,'\0'); + strcpy(_content,s); +} + +std::string MEDFileString::getRepr() const +{ + return std::string(_content); +} + diff --git a/src/MEDLoader/MEDFileBasis.hxx b/src/MEDLoader/MEDFileBasis.hxx new file mode 100644 index 000000000..6e5394691 --- /dev/null +++ b/src/MEDLoader/MEDFileBasis.hxx @@ -0,0 +1,61 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEBASIS_HXX__ +#define __MEDFILEBASIS_HXX__ + +#include "InterpKernelException.hxx" + +#include +#include + +namespace ParaMEDMEM +{ + class MEDFileString + { + public: + MEDFileString(int maxLgth); + ~MEDFileString(); + void set(const char *s) throw(INTERP_KERNEL::Exception); + char *getPointer() { return _content; } + const char *getReprForWrite() const { return _content; } + std::string getRepr() const; + private: + int _max_lgth; + char *_content; + }; + + + class MEDFileMultiString + { + public: + MEDFileMultiString(int nbOfCompo, int maxLgthPerCompo); + ~MEDFileMultiString(); + void set(int compoId, const char *s); + const char *getReprForWrite() const; + std::vector getRepr() const; + std::string getReprPerComp(int compId) const; + private: + int _nb_of_comp; + int _max_lgth_per_comp; + char *_content; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx new file mode 100644 index 000000000..d5d19b4d2 --- /dev/null +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -0,0 +1,213 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileMesh.hxx" +#include "MEDFileUtilities.hxx" +#include "MEDLoaderBase.hxx" + +#include + +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]; + +using namespace ParaMEDMEM; + +MEDFileMeshL2::MEDFileMeshL2():_name(MED_TAILLE_NOM),_description(MED_TAILLE_DESC) +{ +} + +MEDFileUMeshL2::MEDFileUMeshL2() +{ +} + +void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const char *mName) +{ + _name.set(mName); + med_maillage type_maillage; + med_int Mdim; + MEDmaaInfo(fid,mId,(char *)mName,&Mdim,&type_maillage,_description.getPointer()); + if(type_maillage!=MED_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;jalloc(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); + for(int i=0;isetInfoOnComponent(i,info.c_str()); + } + delete [] comp; + delete [] unit; +} + +void MEDFileUMeshL2::sortTypes() +{ + std::set mdims; + std::vector< MEDCouplingAutoRefCountObjectPtr > tmp(_per_type_mesh[0]); + _per_type_mesh.clear(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::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 >& elt=_per_type_mesh[mdim+1-dim]; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::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); + bool found=false; + int ret; + std::vector ms; + for(int i=0;i(oss,", ")); + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return ret; +} + +MEDFileUMesh::MEDFileUMesh(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) + try + { + MEDFileUtilities::CheckFileForRead(fileName); + med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE); + MEDFileUMeshL2 loaderl2; + loaderl2.loadAll(fid,MEDFileUMeshL2::getMeshIdFromName(fid,mName),mName); + MEDfermer(fid); + } +catch(INTERP_KERNEL::Exception& e) + { + throw e; + } + +MEDFileUMesh::~MEDFileUMesh() +{ +} + +void MEDFileUMesh::write(const char *fileName, int mode) const +{ +} + +int MEDFileUMesh::getNumberOfLevels() const +{ + return -1; +} + +MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMax, const char *grp) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=grp; + return getGroups(meshDimRelToMax,tmp); +} + +MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMax, const std::vector& grps) const throw(INTERP_KERNEL::Exception) +{ + return 0; +} + +MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMax, const char *fam) const throw(INTERP_KERNEL::Exception) +{ + std::vector tmp(1); + tmp[0]=fam; + return getFamilies(meshDimRelToMax,tmp); +} + +MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMax, const std::vector& fams) const throw(INTERP_KERNEL::Exception) +{ + return 0; +} + +MEDCouplingUMesh *MEDFileUMesh::getMeshAtRank(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) +{ + return 0; +} + +MEDCouplingUMesh *MEDFileUMesh::getRank0Mesh() const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtRank(0); +} + +MEDCouplingUMesh *MEDFileUMesh::getRankM1Mesh() const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtRank(-1); +} + +MEDCouplingUMesh *MEDFileUMesh::getRankM2Mesh() const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtRank(-2); +} + +MEDCouplingUMesh *MEDFileUMesh::getRankM3Mesh() const throw(INTERP_KERNEL::Exception) +{ + return getMeshAtRank(-3); +} + diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx new file mode 100644 index 000000000..a530fdf5a --- /dev/null +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -0,0 +1,123 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEMESH_HXX__ +#define __MEDFILEMESH_HXX__ + +#include "MEDFileBasis.hxx" +#include "MEDFileMeshElt.hxx" + +#include "MEDCouplingAutoRefCountObjectPtr.hxx" + +extern "C" +{ +#include "med.h" +} + +#include + +namespace ParaMEDMEM +{ + class MEDCouplingUMesh; + + class MEDFileMeshL2 : public RefCountObject + { + public: + MEDFileMeshL2(); + protected: + MEDFileString _name; + MEDFileString _description; + }; + + 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); + static int getMeshIdFromName(med_idt fid, const char *mname) throw(INTERP_KERNEL::Exception); + private: + void sortTypes(); + private: + std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr > > _per_type_mesh; + MEDCouplingAutoRefCountObjectPtr _coords; + }; + + class MEDFileUMeshL2CMesh : public MEDFileMeshL2 + { + }; + + class MEDFileUMeshSplitL1 : public RefCountObject + { + public: + + private: + MEDCouplingUMesh *_m_by_types; + DataArrayInt *_fam; + DataArrayInt *_num; + MEDCouplingUMesh *_m; + }; + + class MEDFileMesh : public RefCountObject + { + public: + static MEDFileMesh *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + 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(); } + protected: + std::string _name; + std::string _univ_name; + std::string _desc_name; + }; + + class MEDFileUMesh : public MEDFileMesh + { + public: + MEDFileUMesh(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); + ~MEDFileUMesh(); + void write(const char *fileName, int mode) const; + int getNumberOfLevels() const; + MEDCouplingUMesh *getGroup(int meshDimRelToMax, const char *grp) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getGroups(int meshDimRelToMax, const std::vector& grps) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getFamily(int meshDimRelToMax, const char *fam) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getFamilies(int meshDimRelToMax, const std::vector& fams) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getMeshAtRank(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getRank0Mesh() const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getRankM1Mesh() const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getRankM2Mesh() const throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *getRankM3Mesh() const throw(INTERP_KERNEL::Exception); + private: + std::vector< MEDCouplingAutoRefCountObjectPtr > _ms; + std::map > _groups; + std::map _families; + }; + + // class MEDFileCMesh : public MEDFileMesh + // { + // public: + + // }; +} + +#endif diff --git a/src/MEDLoader/MEDFileMeshElt.cxx b/src/MEDLoader/MEDFileMeshElt.cxx new file mode 100644 index 000000000..6524e8b3e --- /dev/null +++ b/src/MEDLoader/MEDFileMeshElt.cxx @@ -0,0 +1,181 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileMeshElt.hxx" + +#include "CellModel.hxx" + +using namespace ParaMEDMEM; + +MEDFileUMeshPerType *MEDFileUMeshPerType::New(med_idt fid, const char *mName, int mdim, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType geoElt2) +{ + med_entite_maillage whichEntity; + if(!isExisting(fid,mName,geoElt,whichEntity)) + return 0; + return new MEDFileUMeshPerType(fid,mName,mdim,geoElt,geoElt2,whichEntity); +} + +bool MEDFileUMeshPerType::isExisting(med_idt fid, const char *mName, med_geometrie_element geoElt, med_entite_maillage& whichEntity) +{ + static const med_entite_maillage entities[3]={MED_MAILLE,MED_FACE,MED_ARETE}; + int nbOfElt=0; + for(int i=0;i<3;i++) + { + int tmp=MEDnEntMaa(fid,(char *)mName,MED_CONN,entities[i],geoElt,MED_NOD); + if(tmp>nbOfElt) + { + nbOfElt=tmp; + whichEntity=entities[i]; + } + } + return nbOfElt>0; +} + +int MEDFileUMeshPerType::getDim() const +{ + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(_type); + return cm.getDimension(); +} + +void MEDFileUMeshPerType::write(med_idt fid) const +{ +} + +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) +{ + int curNbOfElem=MEDnEntMaa(fid,(char *)mName,MED_CONN,entity,geoElt,MED_NOD); + if(type!=INTERP_KERNEL::NORM_POLYGON && type!=INTERP_KERNEL::NORM_POLYHED) + { + loadFromStaticType(fid,mName,mdim,curNbOfElem,geoElt,type,entity); + return; + } + if(type==INTERP_KERNEL::NORM_POLYGON) + { + loadPolyg(fid,mName,mdim,curNbOfElem,geoElt,type,entity); + return; + } + //if(type==INTERP_KERNEL::NORM_POLYHED) + loadPolyh(fid,mName,mdim,curNbOfElem,geoElt,type,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) +{ + _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]; + _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; + int *w1=_conn->getPointer(); + int *w2=_conn_index->getPointer(); + *w2++=0; + const int *wi=connTab; + for(int i;i(),-1)); + *w2++=curNbOfElem+1; + } + delete [] connTab; + if(!inuele) + _num=0; +} + +void MEDFileUMeshPerType::loadPolyg(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type, + med_entite_maillage entity) +{ + med_int arraySize; + MEDpolygoneInfo(fid,(char *)mName,entity,MED_NOD,&arraySize); + _conn_index=DataArrayInt::New(); + _conn_index->alloc(curNbOfElem+1,1); + _conn=DataArrayInt::New(); + _conn->alloc(arraySize+curNbOfElem,1); + _num=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); + int *w1=_conn->getPointer(); + int *w2=_conn_index->getPointer(); + const int *wi=locConn; + for(int i=0;i(),-1)); + *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) + _num=0; +} + +void MEDFileUMeshPerType::loadPolyh(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type, + med_entite_maillage 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]; + _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); + int arraySize=connFaceLgth; + for(int i=0;ialloc(arraySize,1); + int *finalConn=_conn->getPointer(); + _conn_index=DataArrayInt::New(); + _conn_index->alloc(curNbOfElem+1,1); + int *finalIndex=_conn_index->getPointer(); + finalIndex[0]=0; + int *wFinalConn=finalConn; + for(int i=0;i(),-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) + _num=0; +} diff --git a/src/MEDLoader/MEDFileMeshElt.hxx b/src/MEDLoader/MEDFileMeshElt.hxx new file mode 100644 index 000000000..892ffdd08 --- /dev/null +++ b/src/MEDLoader/MEDFileMeshElt.hxx @@ -0,0 +1,61 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEMESHELT_HXX__ +#define __MEDFILEMESHELT_HXX__ + +#include "MEDCouplingMemArray.hxx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" + +#include "NormalizedUnstructuredMesh.hxx" + +extern "C" +{ +#include "med.h" +} + +namespace ParaMEDMEM +{ + 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); + int getDim() const; + void write(med_idt fid) const; + 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, INTERP_KERNEL::NormalizedCellType type, + med_entite_maillage entity); + void loadPolyh(med_idt fid, const char *mName, int mdim, int curNbOfElem, med_geometrie_element geoElt, INTERP_KERNEL::NormalizedCellType type, + med_entite_maillage entity); + private: + MEDCouplingAutoRefCountObjectPtr _conn; + MEDCouplingAutoRefCountObjectPtr _conn_index; + MEDCouplingAutoRefCountObjectPtr _num; + MEDCouplingAutoRefCountObjectPtr _fam; + INTERP_KERNEL::NormalizedCellType _type; + med_entite_maillage _entity; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileUtilities.cxx b/src/MEDLoader/MEDFileUtilities.cxx new file mode 100644 index 000000000..9b772c72e --- /dev/null +++ b/src/MEDLoader/MEDFileUtilities.cxx @@ -0,0 +1,89 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDFileUtilities.hxx" +#include "MEDLoaderBase.hxx" + +#include + +med_mode_acces MEDFileUtilities::TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception) +{ + switch(medloaderwritemode) + { + case 2: + return MED_CREATION; + case 1: + return MED_LECTURE_AJOUT; + case 0: + return MED_LECTURE_ECRITURE; + default: + throw INTERP_KERNEL::Exception("Invalid write mode specified ! must be 0(write with no question), 1(append) or 2(creation)"); + } +} + +void MEDFileUtilities::CheckMEDCode(int code, const char *msg) throw(INTERP_KERNEL::Exception) +{ + if(code!=0) + { + std::ostringstream oss; + oss << "MEDFile has returned an error code (" << code <<") : "; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } +} + +void MEDFileUtilities::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception) +{ + int status=MEDLoaderBase::getStatusOfFile(fileName); + std::ostringstream oss; + oss << " File : \"" << fileName << "\""; + switch(status) + { + case MEDLoaderBase::DIR_LOCKED: + { + oss << " has been detected as unreadable : impossible to read anything !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + case MEDLoaderBase::NOT_EXIST: + { + oss << " has been detected as NOT EXISTING : impossible to read anything !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + case MEDLoaderBase::EXIST_WRONLY: + { + oss << " has been detected as WRITE ONLY : impossible to read anything !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + int fid=MEDouvrir((char *)fileName,MED_LECTURE); + if(fid<0) + { + oss << " has been detected as unreadable by MED file : impossible to read anything !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + oss << " has been detected readable but "; + int major,minor,release; + MEDversionLire(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); +} diff --git a/src/MEDLoader/MEDFileUtilities.hxx b/src/MEDLoader/MEDFileUtilities.hxx new file mode 100644 index 000000000..a88213325 --- /dev/null +++ b/src/MEDLoader/MEDFileUtilities.hxx @@ -0,0 +1,37 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __MEDFILEUTILITIES_HXX__ +#define __MEDFILEUTILITIES_HXX__ + +#include "InterpKernelException.hxx" + +extern "C" +{ +#include "med.h" +} + +namespace MEDFileUtilities +{ + med_mode_acces TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception); + void CheckMEDCode(int code, const char *msg) throw(INTERP_KERNEL::Exception); + void CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception); +} + +#endif diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index cde077cee..616831a2d 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -19,6 +19,7 @@ #include "MEDLoader.hxx" #include "MEDLoaderBase.hxx" +#include "MEDFileUtilities.hxx" #include "CellModel.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingMemArray.hxx" @@ -300,43 +301,7 @@ void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception) diff --git a/src/MEDLoader/Makefile.am b/src/MEDLoader/Makefile.am index 3a2fbb760..4cdf0f72c 100755 --- a/src/MEDLoader/Makefile.am +++ b/src/MEDLoader/Makefile.am @@ -36,10 +36,11 @@ lib_LTLIBRARIES = libmedloader.la salomeinclude_HEADERS= \ MEDLoaderDefines.hxx \ -MEDLoader.hxx MEDLoaderBase.hxx +MEDLoader.hxx MEDLoaderBase.hxx MEDFileUtilities.hxx MEDFileMesh.hxx dist_libmedloader_la_SOURCES= \ -MEDLoader.cxx MEDLoaderBase.cxx +MEDLoader.cxx MEDLoaderBase.cxx MEDFileUtilities.cxx \ +MEDFileMesh.cxx MEDFileMeshElt.cxx MEDFileBasis.cxx libmedloader_la_CPPFLAGS= $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ -I$(srcdir)/../INTERP_KERNEL \