--- /dev/null
+// 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 <cstring>
+
+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);
+}
+
--- /dev/null
+// 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 <string>
+#include <vector>
+
+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<std::string> getRepr() const;
+ std::string getReprPerComp(int compId) const;
+ private:
+ int _nb_of_comp;
+ int _max_lgth_per_comp;
+ char *_content;
+ };
+}
+
+#endif
--- /dev/null
+// 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 <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];
+
+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;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);
+ 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()
+{
+ 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);
+ bool found=false;
+ int ret;
+ std::vector<std::string> ms;
+ for(int i=0;i<n;i++)
+ {
+ MEDmaaInfo(fid,i+1,nommaa,&dim,&type_maillage,maillage_description);
+ std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
+ ms.push_back(cur);
+ if(cur==mname)
+ {
+ found=true;
+ ret=i;
+ }
+ }
+ if(!found)
+ {
+ std::ostringstream oss;
+ oss << "No such meshname in file ! Must be in :";
+ std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(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<std::string> tmp(1);
+ tmp[0]=grp;
+ return getGroups(meshDimRelToMax,tmp);
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMax, const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception)
+{
+ return 0;
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMax, const char *fam) const throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> tmp(1);
+ tmp[0]=fam;
+ return getFamilies(meshDimRelToMax,tmp);
+}
+
+MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMax, const std::vector<std::string>& 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);
+}
+
--- /dev/null
+// 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 <map>
+
+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<MEDFileUMeshPerType> > > _per_type_mesh;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _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<std::string>& 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<std::string>& 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<MEDFileUMeshSplitL1> > _ms;
+ std::map<std::string, std::vector<std::string> > _groups;
+ std::map<std::string,int> _families;
+ };
+
+ // class MEDFileCMesh : public MEDFileMesh
+ // {
+ // public:
+
+ // };
+}
+
+#endif
--- /dev/null
+// 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<curNbOfElem;i++,wi+=curNbOfElem)
+ {
+ *w1++=(int)type;
+ w1=std::transform(wi,wi+curNbOfElem,w1,std::bind2nd(std::plus<int>(),-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<curNbOfElem;i++,w2++)
+ {
+ *w1++=(int)type;
+ w1=std::transform(wi,wi+(w2[1]-w2[0]),w1,std::bind2nd(std::plus<int>(),-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;i<curNbOfElem;i++)
+ arraySize+=index[i+1]-index[i]-1;
+ _conn=DataArrayInt::New();
+ _conn->alloc(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<curNbOfElem;i++)
+ {
+ finalIndex[i+1]=finalIndex[i]+index[i+1]-index[i]-1+indexFace[index[i+1]-1]-indexFace[index[i]-1];
+ wFinalConn=std::copy(locConn+indexFace[index[i]-1]-1,locConn+indexFace[index[i]]-1,wFinalConn);
+ for(int j=index[i];j<index[i+1]-1;j++)
+ {
+ *wFinalConn++=-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)
+ _num=0;
+}
--- /dev/null
+// 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<DataArrayInt> _conn;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _conn_index;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _num;
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> _fam;
+ INTERP_KERNEL::NormalizedCellType _type;
+ med_entite_maillage _entity;
+ };
+}
+
+#endif
--- /dev/null
+// 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 <sstream>
+
+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);
+}
--- /dev/null
+// 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
#include "MEDLoader.hxx"
#include "MEDLoaderBase.hxx"
+#include "MEDFileUtilities.hxx"
#include "CellModel.hxx"
#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingMemArray.hxx"
void MEDLoader::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);
+ MEDFileUtilities::CheckFileForRead(fileName);
}
std::vector<std::string> MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception)
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 \