- }
- MEDfileClose(fid);
- return ret;
-}
-
-/*!
- * This method reads all the content of a field 'fieldName' at a time specified by (iteration,order) lying on a mesh 'meshName' with a specified type 'TypeOfOutField'
- * The returned values are strored in 'field' (sorted by type of cell), time corresponding to field, and 'infos' to load properly little strings.
- * The principle of this method is to put into 'field' only data that fulfills \b perfectly request.
- */
-void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName,
- int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField,
- std::list<MEDLoader::MEDFieldDoublePerCellType>& field,
- double& time, std::vector<std::string>& infos)
-{
- time=0.;
- MEDFileUtilities::CheckFileForRead(fileName);
- MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
- med_int nbFields=MEDnField(fid);
- //
- 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;
- med_bool localmesh;
- bool found=false;
- tabEnt[ON_CELLS]=MED_CELL;
- tabType[ON_CELLS]=typmai;
- 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_CELL;
- tabType[ON_GAUSS_PT]=typmai;
- 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_N_CELL_FIXED_GEO;
- //
- for(int i=0;i<nbFields && !found;i++)
- {
- 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);
- std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
- found=(curFieldName==fieldName) && (curMeshName==meshName);
- if(found)
- {
- infos.resize(ncomp);
- for(int ii=0;ii<ncomp;ii++)
- infos[ii]=MEDLoaderBase::buildUnionUnit(comp+ii*MED_SNAME_SIZE,MED_SNAME_SIZE,unit+ii*MED_SNAME_SIZE,MED_SNAME_SIZE);
- 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;
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- for(int j=0;j<tabTypeLgth[typeOfOutField];j++)
- {
- if(nbPdt>0)
- {
- INTERP_KERNEL::AutoPtr<char> pflDummy=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
- INTERP_KERNEL::AutoPtr<char> locDummy=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
- int nbProfiles=MEDfieldnProfile(fid,fieldName,numdt,numo,tabEnt[typeOfOutField],tabType[typeOfOutField][j],pflDummy,locDummy);
- for(int kk=0;kk<nbProfiles;kk++)
- {
- int profilesize,nbi;
- int nval=MEDfieldnValueWithProfile(fid,fieldName,numdt,numo,tabEnt[typeOfOutField],tabType[typeOfOutField][j],kk+1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi);
- if(nval>0)
- {
- 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));
- }
- }
- }
- }
- }
- }
- if(!found)
- {
- std::ostringstream oss; oss << "MEDLoaderNS::readFieldDoubleDataInMedFile : no such couple meshName=\"" << meshName << "\", fieldName=\"" << fieldName << "\" in file \"" << fileName << "\" !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
-}
-
-std::vector<int> MEDLoaderNS::getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector<std::string>& fams)
-{
- std::vector<int> ret;
- 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=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);
- }
- 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=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=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_LNAME_SIZE,MED_LNAME_SIZE);
- if(std::find(grps.begin(),grps.end(),cur2)!=grps.end())
- {
- ret.push_back(numfam);
- break;
- }
- }
- }
- MEDfileClose(fid);
- return ret;
-}
-
-med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception)
-{
- if(meshName==0)
- {
- std::vector<std::string> meshes=getMeshNamesFid(fid);
- if(meshes.empty())
- throw INTERP_KERNEL::Exception("No mesh in file");
- trueMeshName=meshes[0];
- return 1;
- }
- std::string meshNameStr(meshName);
- std::vector<std::string> meshes=getMeshNamesFid(fid);
- if(meshes.empty())
- throw INTERP_KERNEL::Exception("No mesh in file");
- std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
- if(iter==meshes.end())
- {
- std::ostringstream os2;
- os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
- std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
- throw INTERP_KERNEL::Exception(os2.str().c_str());
- }
- trueMeshName=meshName;
- return iter-meshes.begin()+1;
-}
-
-/*!
- * This methods allows to merger all entities and to considerate only cell types.
- */
-void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
-{
- if(nbOfElemCell>=nbOfElemFace)
- {
- whichEntity=MED_CELL;
- nbOfElem=nbOfElemCell;
- }
- else
- {
- whichEntity=MED_CELL;
- nbOfElem=nbOfElemFace;
- }
-}
-
-/*!
- * This method returns a first quick overview of mesh with name 'meshName' into the file 'fileName'.
- * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
- * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
- */
-int MEDLoaderNS::readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector<int>& possibilities)
-{
- possibilities.clear();
- med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
- int ret;
- std::set<int> poss;
- 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);
- 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_entity_type whichEntity;
- MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
- if(curNbOfElem>0)
- {
- INTERP_KERNEL::NormalizedCellType type=typmai2[i];
- int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
- poss.insert(curDim);
- }
- }
- MEDfileClose(fid);
- if(!poss.empty())
- {
- ret=*poss.rbegin();
- for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
- possibilities.push_back(*it-ret);
- }
- else
- ret=-2;
- return ret;
-}
-
-void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn, std::string& description)
-{
- char nommaa[MED_NAME_SIZE+1];
- char maillage_description[MED_COMMENT_SIZE+1];
- med_mesh_type type_maillage;
- med_int Mdim;
- 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();
- MEDmeshNodeCoordinateRd(fid,nommaa,numdt,numit,MED_FULL_INTERLACE,coordsPtr);
- for(int i=0;i<spaceDim;i++)
- {
- 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());
- }
- for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
- {
- 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);
- 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
- if(withnumber)
- elem.setGlobal(globArr);
- else
- delete [] globArr;
- //limitation manage withfam==false
- conn.push_back(elem);
- }
- }
- int curNbOfPolyElem;
- 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=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);
- 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=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1;
- if(curNbOfPolyElem>0)
- {
- med_int indexFaceLgth,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];
- 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;
- int *finalConn=new int[arraySize];
- int *finalIndex=new int[curNbOfPolyElem+1];
- finalIndex[0]=1;
- int *wFinalConn=finalConn;
- for(int i=0;i<curNbOfPolyElem;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++=0;
- wFinalConn=std::copy(locConn+indexFace[j]-1,locConn+indexFace[j+1]-1,wFinalConn);
- }
- }
- MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYHED,finalConn,finalIndex,fam,curNbOfPolyElem,arraySize);
- 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;
- }