1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDLoader.hxx"
22 #include "MEDLoaderBase.hxx"
23 #include "MEDFileUtilities.hxx"
24 #include "MEDFileMesh.hxx"
25 #include "MEDFileField.hxx"
26 #include "CellModel.hxx"
27 #include "MEDCouplingUMesh.hxx"
28 #include "MEDCouplingMemArray.hxx"
29 #include "MEDCouplingFieldDouble.hxx"
30 #include "MEDCouplingGaussLocalization.hxx"
31 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
33 #include "InterpKernelAutoPtr.hxx"
46 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
69 med_geometry_type typmainoeud[1] = { MED_NONE };
71 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
72 INTERP_KERNEL::NORM_SEG2,
73 INTERP_KERNEL::NORM_SEG3,
74 INTERP_KERNEL::NORM_SEG4,
75 INTERP_KERNEL::NORM_TRI3,
76 INTERP_KERNEL::NORM_QUAD4,
77 INTERP_KERNEL::NORM_TRI6,
78 INTERP_KERNEL::NORM_TRI7,
79 INTERP_KERNEL::NORM_QUAD8,
80 INTERP_KERNEL::NORM_QUAD9,
81 INTERP_KERNEL::NORM_TETRA4,
82 INTERP_KERNEL::NORM_PYRA5,
83 INTERP_KERNEL::NORM_PENTA6,
84 INTERP_KERNEL::NORM_HEXA8,
85 INTERP_KERNEL::NORM_HEXGP12,
86 INTERP_KERNEL::NORM_TETRA10,
87 INTERP_KERNEL::NORM_PYRA13,
88 INTERP_KERNEL::NORM_PENTA15,
89 INTERP_KERNEL::NORM_HEXA20,
90 INTERP_KERNEL::NORM_HEXA27,
91 INTERP_KERNEL::NORM_POLYGON,
92 INTERP_KERNEL::NORM_POLYHED };
94 med_geometry_type typmai3[34] = { MED_POINT1,//0
130 double MEDLoader::_EPS_FOR_NODE_COMP=1.e-12;
132 int MEDLoader::_COMP_FOR_CELL=0;
134 int MEDLoader::_TOO_LONG_STR=0;
136 using namespace ParaMEDMEM;
140 namespace MEDLoaderNS
142 int readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector<int>& possibilities);
143 void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity);
144 void writeFieldWithoutReadingAndMappingOfMeshInFile(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch);
145 med_int getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception);
146 std::vector<std::string> getMeshNamesFid(med_idt fid);
155 * This method returns a first quick overview of mesh with name 'meshName' into the file 'fileName'.
156 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
157 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
159 int MEDLoaderNS::readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector<int>& possibilities)
161 possibilities.clear();
162 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
165 char nommaa[MED_NAME_SIZE+1];
166 char maillage_description[MED_COMMENT_SIZE+1];
167 med_mesh_type type_maillage;
169 std::string trueMeshName;
170 med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
171 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
172 med_sorting_type sortingType;
174 med_axis_type axisType;
175 int naxis=MEDmeshnAxis(fid,meshId);
176 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
177 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
178 MEDmeshInfo(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit);
182 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
186 MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
188 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
190 med_geometry_type curMedType=typmai[i];
191 med_bool changement,transformation;
192 int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
193 int curNbOfElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);//limitation
195 med_entity_type whichEntity;
196 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
199 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
200 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
207 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
208 possibilities.push_back(*it-ret);
215 med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception)
219 std::vector<std::string> meshes=getMeshNamesFid(fid);
221 throw INTERP_KERNEL::Exception("No mesh in file");
222 trueMeshName=meshes[0];
225 std::string meshNameStr(meshName);
226 std::vector<std::string> meshes=getMeshNamesFid(fid);
228 throw INTERP_KERNEL::Exception("No mesh in file");
229 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
230 if(iter==meshes.end())
232 std::ostringstream os2;
233 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
234 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
235 throw INTERP_KERNEL::Exception(os2.str().c_str());
237 trueMeshName=meshName;
238 return iter-meshes.begin()+1;
241 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
243 med_mesh_type type_maillage;
244 char maillage_description[MED_COMMENT_SIZE+1];
245 char dtunit[MED_COMMENT_SIZE+1];
248 char nommaa[MED_NAME_SIZE+1];
249 med_axis_type axistype;
250 med_sorting_type stype;
251 med_int n=MEDnMesh(fid);
252 std::vector<std::string> ret(n);
255 int naxis=MEDmeshnAxis(fid,i+1);
256 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
257 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
259 MEDmeshInfo(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit);
260 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
267 * This methods allows to merger all entities and to considerate only cell types.
269 void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
271 if(nbOfElemCell>=nbOfElemFace)
273 whichEntity=MED_CELL;
274 nbOfElem=nbOfElemCell;
278 whichEntity=MED_CELL;
279 nbOfElem=nbOfElemFace;
286 * This method sets the epsilon value used for node comparison when trying to buid a profile for a field on node/cell on an already written mesh.
288 void MEDLoader::SetEpsilonForNodeComp(double val) throw(INTERP_KERNEL::Exception)
290 _EPS_FOR_NODE_COMP=val;
294 * This method sets the policy comparison when trying to fit the already written mesh on a field. The semantic of the policy is specified in MEDCouplingUMesh::zipConnectivityTraducer.
296 void MEDLoader::SetCompPolicyForCell(int val) throw(INTERP_KERNEL::Exception)
302 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
303 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
305 void MEDLoader::SetTooLongStrPolicy(int val) throw(INTERP_KERNEL::Exception)
311 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
312 * It returns, in this order :
313 * - number of cells sorted by dimension and by geometry type. The first entry in the vector is the maximal dimension, the 2nd in the vector is the maximal dimension-1...
314 * - the mesh dimension
315 * - the space dimension
316 * - the number of nodes
318 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > MEDLoader::GetUMeshGlobalInfo(const char *fileName, const char *meshName, int &meshDim, int& spaceDim, int& numberOfNodes) throw(INTERP_KERNEL::Exception)
320 CheckFileForRead(fileName);
321 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
323 char nommaa[MED_NAME_SIZE+1];
324 char maillage_description[MED_COMMENT_SIZE+1];
325 med_mesh_type type_maillage;
326 std::string trueMeshName;
327 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
328 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
329 med_sorting_type sortingType;
331 med_axis_type axisType;
332 int naxis=MEDmeshnAxis(fid,meshId);
333 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
334 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
335 MEDmeshInfo(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit);
336 if(type_maillage!=MED_UNSTRUCTURED_MESH)
338 std::ostringstream oss; oss << "MEDLoader::GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
339 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
340 throw INTERP_KERNEL::Exception(oss.str().c_str());
344 throw INTERP_KERNEL::Exception("MEDLoader::GetUMeshGlobalInfo : multisteps on mesh not managed !");
347 MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
349 std::vector<int> dims;
350 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
351 med_bool changement,transformation;
352 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
354 med_geometry_type curMedType=typmai[i];
355 int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
358 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
359 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
360 dims.push_back(mdimCell);
361 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
364 int maxLev=*std::max_element(dims.begin(),dims.end());
365 int lowLev=*std::min_element(dims.begin(),dims.end());
366 int nbOfLevels=maxLev-lowLev+1;
367 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
368 for(std::size_t i=0;i<dims.size();i++)
370 ret[maxLev-dims[i]].push_back(geoTypes[i]);
372 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
376 void MEDLoader::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception)
378 MEDFileUtilities::CheckFileForRead(fileName);
381 std::vector<std::string> MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception)
383 CheckFileForRead(fileName);
384 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
385 std::vector<std::string> ret=MEDLoaderNS::getMeshNamesFid(fid);
389 std::vector< std::pair<std::string,std::string> > MEDLoader::GetComponentsNamesOfField(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
391 CheckFileForRead(fileName);
392 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
393 med_int nbFields=MEDnField(fid);
394 std::vector<std::string> fields(nbFields);
395 med_field_type typcha;
396 for(int i=0;i<nbFields;i++)
398 med_int ncomp=MEDfieldnComponent(fid,i+1);
399 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
400 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
401 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
404 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
405 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
406 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
407 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
408 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
409 if(curFieldName==fieldName)
411 std::vector< std::pair<std::string,std::string> > ret(ncomp);
412 for(int j=0;j<ncomp;j++)
413 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
414 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
417 fields[i]=curFieldName;
419 std::ostringstream oss; oss << "MEDLoader::GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
420 oss << "Possible field names are : " << std::endl;
421 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
422 throw INTERP_KERNEL::Exception(oss.str().c_str());
425 std::vector<std::string> MEDLoader::GetMeshNamesOnField(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
427 CheckFileForRead(fileName);
428 std::vector<std::string> ret;
430 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
431 med_int nbFields=MEDnField(fid);
433 med_field_type typcha;
434 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
435 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
438 for(int i=0;i<nbFields;i++)
440 med_int ncomp=MEDfieldnComponent(fid,i+1);
441 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
442 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
444 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
445 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
446 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
447 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
448 if(curFieldName==fieldName)
449 ret.push_back(meshName);
454 std::vector<std::string> MEDLoader::GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
456 CheckFileForRead(fileName);
457 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
458 med_int nfam=MEDnFamily(fid,meshName);
459 std::vector<std::string> ret(nfam);
460 char nomfam[MED_NAME_SIZE+1];
462 for(int i=0;i<nfam;i++)
464 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
465 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
466 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
467 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
468 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
469 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
470 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
471 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
478 std::vector<std::string> MEDLoader::GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception)
480 CheckFileForRead(fileName);
481 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
482 med_int nfam=MEDnFamily(fid,meshName);
483 std::vector<std::string> ret;
484 char nomfam[MED_NAME_SIZE+1];
486 for(int i=0;i<nfam;i++)
488 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
489 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
490 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
491 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
492 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
493 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
494 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
495 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
496 for(int j=0;j<ngro;j++)
498 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
506 std::vector<std::string> MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception)
508 CheckFileForRead(fileName);
509 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
510 med_int nfam=MEDnFamily(fid,meshName);
511 std::vector<std::string> ret;
512 char nomfam[MED_NAME_SIZE+1];
515 for(int i=0;i<nfam && !found;i++)
517 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
518 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
519 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
520 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
521 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
522 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
523 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
524 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
525 found=(cur==famName);
527 for(int j=0;j<ngro;j++)
529 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
535 std::ostringstream oss;
536 oss << "MEDLoader::GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
537 throw INTERP_KERNEL::Exception(oss.str().c_str());
543 std::vector<std::string> MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
545 CheckFileForRead(fileName);
546 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
547 med_int nfam=MEDnFamily(fid,meshName);
548 std::vector<std::string> ret;
549 char nomfam[MED_NAME_SIZE+1];
551 for(int i=0;i<nfam;i++)
553 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
554 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
555 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
556 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
557 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
558 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
559 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
560 for(int j=0;j<ngro;j++)
562 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
563 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
569 std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
571 CheckFileForRead(fileName);
572 std::vector<ParaMEDMEM::TypeOfField> ret;
573 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
574 med_int nbFields=MEDnField(fid);
576 med_field_type typcha;
577 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
578 med_int numdt=0,numo=0;
580 char pflname[MED_NAME_SIZE+1]="";
581 char locname[MED_NAME_SIZE+1]="";
582 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
583 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
586 for(int i=0;i<nbFields;i++)
588 med_int ncomp=MEDfieldnComponent(fid,i+1);
589 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
590 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
591 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
593 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
594 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
595 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
596 if(curMeshName==meshName)
598 if(curFieldName==fieldName)
604 for(int ii=0;ii<nbPdt && !found;ii++)
606 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
607 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
608 pflname,&profilesize,locname,&nbi);
611 ret.push_back(ON_NODES);
617 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
621 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
622 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
623 pflname,&profilesize,locname,&nbi);
627 ret.push_back(ON_CELLS);
639 std::vector<std::string> MEDLoader::GetAllFieldNames(const char *fileName) throw(INTERP_KERNEL::Exception)
641 CheckFileForRead(fileName);
642 std::vector<std::string> ret;
643 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
644 med_int nbFields=MEDnField(fid);
645 med_field_type typcha;
646 for(int i=0;i<nbFields;i++)
648 med_int ncomp=MEDfieldnComponent(fid,i+1);
649 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
650 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
651 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
652 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
653 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
656 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
657 ret.push_back(std::string(nomcha));
662 std::vector<std::string> MEDLoader::GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
664 CheckFileForRead(fileName);
665 std::vector<std::string> ret;
666 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
667 med_int nbFields=MEDnField(fid);
669 med_field_type typcha;
670 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
671 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
673 for(int i=0;i<nbFields;i++)
675 med_int ncomp=MEDfieldnComponent(fid,i+1);
676 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
677 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
678 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
681 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
682 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
683 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
685 if(curMeshName==meshName)
686 ret.push_back(curFieldName);
693 std::vector<std::string> MEDLoader::GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
695 CheckFileForRead(fileName);
699 return GetCellFieldNamesOnMesh(fileName,meshName);
701 return GetNodeFieldNamesOnMesh(fileName,meshName);
703 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
707 std::vector<std::string> MEDLoader::GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
709 CheckFileForRead(fileName);
710 std::vector<std::string> ret;
711 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
712 med_int nbFields=MEDnField(fid);
714 med_field_type typcha;
715 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
716 med_int numdt=0,numo=0;
718 char pflname[MED_NAME_SIZE+1]="";
719 char locname[MED_NAME_SIZE+1]="";
720 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
721 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
722 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
726 for(int i=0;i<nbFields;i++)
728 med_int ncomp=MEDfieldnComponent(fid,i+1);
729 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
730 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
731 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
732 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
733 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
735 if(curMeshName==meshName)
738 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
742 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
743 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
744 pflname,&profilesize,locname,&nbi);
748 ret.push_back(curFieldName);
757 std::vector<std::string> MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
759 CheckFileForRead(fileName);
760 std::vector<std::string> ret;
761 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
762 med_int nbFields=MEDnField(fid);
763 char pflname[MED_NAME_SIZE+1]="";
764 char locname[MED_NAME_SIZE+1]="";
766 med_field_type typcha;
767 med_int numdt=0,numo=0;
769 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
770 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
771 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
774 for(int i=0;i<nbFields;i++)
776 med_int ncomp=MEDfieldnComponent(fid,i+1);
777 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
778 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
780 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
781 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
782 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
786 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
787 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
788 pflname,&profilesize,locname,&nbi);
789 if(curMeshName==meshName && nbOfVal>0)
791 ret.push_back(curFieldName);
798 std::vector< std::pair< std::pair<int,int>, double> > MEDLoader::GetAllFieldIterations(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
800 CheckFileForRead(fileName);
801 std::vector< std::pair< std::pair<int,int>, double > > ret;
802 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
803 med_int nbFields=MEDnField(fid);
805 med_field_type typcha;
806 med_int numdt=0,numo=0;
808 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
809 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
810 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
813 std::ostringstream oss; oss << "MEDLoader::GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
814 for(int i=0;i<nbFields;i++)
816 med_int ncomp=MEDfieldnComponent(fid,i+1);
817 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
818 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
820 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
821 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
822 if(curFieldName==fieldName)
824 for(int k=0;k<nbPdt;k++)
826 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
827 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
833 oss << "\"" << curFieldName << "\"";
834 if(i!=nbFields-1) oss << ", ";
838 throw INTERP_KERNEL::Exception(oss.str().c_str());
841 double MEDLoader::GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
843 CheckFileForRead(fileName);
844 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
845 med_int nbFields=MEDnField(fid);
847 med_field_type typcha;
848 med_int numdt=0,numo=0;
851 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
852 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
853 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
857 double ret=std::numeric_limits<double>::max();
858 for(int i=0;i<nbFields && !found;i++)
860 med_int ncomp=MEDfieldnComponent(fid,i+1);
861 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
862 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
864 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt);
865 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
866 if(curFieldName==fieldName)
869 for(int k=0;k<nbPdt;k++)
871 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
872 if(numdt==iteration && numo==order)
880 if(!found || !found2)
882 std::ostringstream oss;
883 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
884 throw INTERP_KERNEL::Exception(oss.str().c_str());
889 std::vector< std::pair<int,int> > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
891 CheckFileForRead(fileName);
895 return GetCellFieldIterations(fileName,meshName,fieldName);
897 return GetNodeFieldIterations(fileName,meshName,fieldName);
899 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
903 std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
905 CheckFileForRead(fileName);
906 std::string meshNameCpp(meshName);
907 std::vector< std::pair<int,int> > ret;
908 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
909 med_int nbFields=MEDnField(fid);
911 med_field_type typcha;
912 med_int numdt=0,numo=0;
914 char pflname[MED_NAME_SIZE+1]="";
915 char locname[MED_NAME_SIZE+1]="";
916 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
917 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
918 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
921 std::ostringstream oss; oss << "MEDLoader::GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
922 std::set<std::string> s2;
923 for(int i=0;i<nbFields;i++)
925 med_int ncomp=MEDfieldnComponent(fid,i+1);
926 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
927 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
929 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
930 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
931 if(curFieldName==fieldName)
934 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
936 for(int k=0;k<nbPdt;k++)
939 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
940 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
941 pflname,&profilesize,locname,&nbi);
942 std::string maa_ass_cpp(maa_ass);
945 if(meshNameCpp==maa_ass_cpp)
948 ret.push_back(std::make_pair(numdt,numo));
951 s2.insert(maa_ass_cpp);
958 oss << "\"" << curFieldName << "\"";
959 if(i!=nbFields-1) oss << ", ";
966 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
967 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
970 throw INTERP_KERNEL::Exception(oss.str().c_str());
975 std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
977 CheckFileForRead(fileName);
978 std::string meshNameCpp(meshName);
979 std::vector< std::pair<int,int> > ret;
980 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
981 med_int nbFields=MEDnField(fid);
983 med_field_type typcha;
984 med_int numdt=0,numo=0;
986 char pflname[MED_NAME_SIZE+1]="";
987 char locname[MED_NAME_SIZE+1]="";
988 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
989 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
990 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
993 std::ostringstream oss; oss << "MEDLoader::GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
994 std::set<std::string> s2;
995 for(int i=0;i<nbFields;i++)
997 med_int ncomp=MEDfieldnComponent(fid,i+1);
998 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
999 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1001 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
1002 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1003 if(curFieldName==fieldName)
1005 for(int k=0;k<nbPdt;k++)
1007 int profilesize,nbi;
1008 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
1009 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1010 pflname,&profilesize,locname,&nbi);
1011 std::string maa_ass_cpp(maa_ass);
1014 if(meshNameCpp==maa_ass_cpp)
1015 { ret.push_back(std::make_pair(numdt,numo)); }
1017 s2.insert(maa_ass_cpp);
1023 oss << "\"" << curFieldName << "\"";
1024 if(i!=nbFields-1) oss << ", ";
1031 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1032 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1035 throw INTERP_KERNEL::Exception(oss.str().c_str());
1040 MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
1042 CheckFileForRead(fileName);
1043 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1044 MEDFileMesh *mmPtr(mm);
1045 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1048 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1049 throw INTERP_KERNEL::Exception(oss.str().c_str());
1051 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1054 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
1056 CheckFileForRead(fileName);
1057 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName);
1058 MEDFileMesh *mmPtr(mm);
1059 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1062 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1063 throw INTERP_KERNEL::Exception(oss.str().c_str());
1065 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1068 int MEDLoader::ReadUMeshDimFromFile(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
1070 CheckFileForRead(fileName);
1071 std::vector<int> poss;
1072 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1075 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception)
1077 CheckFileForRead(fileName);
1078 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1079 MEDFileMesh *mmPtr(mm);
1080 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1083 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1084 throw INTERP_KERNEL::Exception(oss.str().c_str());
1086 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1089 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception)
1091 CheckFileForRead(fileName);
1092 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1093 MEDFileMesh *mmPtr(mm);
1094 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1097 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1098 throw INTERP_KERNEL::Exception(oss.str().c_str());
1100 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1103 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadField(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
1105 CheckFileForRead(fileName);
1109 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1111 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1113 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1115 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1117 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1121 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsOnSameMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
1122 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1125 return std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>();
1126 CheckFileForRead(fileName);
1127 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> ret(its.size());
1128 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> > retSafe(its.size());
1131 //Retrieving mesh of rank 0 and field on rank 0 too.
1132 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1133 MEDFileMesh *mmPtr(mm);
1134 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1136 throw INTERP_KERNEL::Exception("MEDLoader::ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1137 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1138 const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1139 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m2(m->clone(true));
1141 m2->renumberCells(o2n->begin(),true);
1143 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1145 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1146 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1148 retElt->renumberCells(o2n->begin(),true);
1149 retElt->setMesh(m2);
1153 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1154 ret[i]=retSafe[i].retn();
1158 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsCellOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
1159 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1161 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1164 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsNodeOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
1165 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1167 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1170 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
1171 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1173 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1176 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussNEOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
1177 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1179 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1182 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
1184 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1185 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1186 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1187 MEDFileMesh *mPtr(mm);
1188 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1189 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_CELLS,m);
1192 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1194 ret->renumberCells(num->begin());
1199 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
1201 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1202 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1203 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1204 MEDFileMesh *mPtr(mm);
1205 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_NODES,m);
1206 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1207 if(ff->getPflsReallyUsed().empty())
1211 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1213 ret->renumberCells(num->begin());
1218 DataArrayInt *pfl=0,*arr2=0;
1219 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl);
1220 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflSafe(pfl);
1221 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> mp=m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end());
1222 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mzip=static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2));
1223 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2Safe(arr2);
1224 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes());
1225 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflSorted(pflSafe->deepCpy()); pflSorted->sort(true);
1226 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1227 throw INTERP_KERNEL::Exception("MEDLoader::ReadFieldNode : not implemented yet !");
1228 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1230 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n2=pflSafe->checkAndPreparePermutation();
1231 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o2=o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples());
1232 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1241 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
1243 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1244 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1245 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1246 MEDFileMesh *mPtr(mm);
1247 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1248 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m);
1251 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1253 ret->renumberCells(num->begin());
1258 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
1260 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1261 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1262 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1263 MEDFileMesh *mPtr(mm);
1264 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1265 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m);
1268 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1270 ret->renumberCells(num->begin());
1275 void MEDLoader::WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
1278 throw INTERP_KERNEL::Exception("MEDLoader::WriteUMesh : input mesh is null !");
1279 int mod=writeFromScratch?2:0;
1280 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m=MEDFileUMesh::New();
1281 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCpy()));
1282 m->setMeshAtLevel(0,mcpy,true);
1283 m->write(fileName,mod);
1286 void MEDLoader::WriteUMeshDep(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
1288 MEDLoader::WriteUMesh(fileName,mesh,writeFromScratch);
1291 void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
1293 std::string meshName(meshNameC);
1294 if(meshName.empty())
1295 throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name : change 2nd parameter !");
1296 int status=MEDLoaderBase::getStatusOfFile(fileName);
1297 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1299 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1300 throw INTERP_KERNEL::Exception(oss.str().c_str());
1302 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m=MEDFileUMesh::New();
1303 m->setGroupsFromScratch(0,meshes,true);
1304 m->setName(meshNameC);
1305 int mod=writeFromScratch?2:0;
1306 m->write(fileName,mod);
1309 void MEDLoader::WriteUMeshesPartitionDep(const char *fileName, const char *meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
1311 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1314 void MEDLoader::WriteUMeshes(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
1316 int mod=writeFromScratch?2:0;
1317 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m=MEDFileUMesh::New();
1318 m->setMeshes(meshes,true);
1319 m->write(fileName,mod);
1322 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1324 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New();
1325 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1326 const MEDCouplingMesh *m=f2->getMesh();
1327 const MEDCouplingUMesh *um=dynamic_cast<const MEDCouplingUMesh *>(m);
1328 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
1329 int mod=writeFromScratch?2:0;
1332 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu=MEDFileUMesh::New();
1333 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=um->getRenumArrForMEDFileFrmt();
1334 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o=o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples());
1335 f2->renumberCells(o2n->begin(),false);
1336 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1337 mmu->setRenumFieldArr(0,n2o);
1338 ff->setFieldNoProfileSBT(f2);
1339 mmu->write(fileName,mod);
1342 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only umeshes are dealed in this API for the moment !");
1343 ff->write(fileName,0);
1346 void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
1349 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : input field is NULL !");
1350 f->checkCoherency();
1351 int status=MEDLoaderBase::getStatusOfFile(fileName);
1352 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1354 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1355 throw INTERP_KERNEL::Exception(oss.str().c_str());
1357 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1359 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
1363 std::vector<std::string> meshNames=GetMeshNames(fileName);
1365 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : trying to write a field with no mesh !");
1366 std::string fileNameCpp(f->getMesh()->getName());
1367 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1368 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
1371 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,f->getMesh()->getName().c_str());
1372 const MEDFileMesh *mmPtr(mm);
1373 const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
1375 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : only umeshes are supported now !");
1376 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1377 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1379 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : only umesh in input field supported !");
1380 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1381 f2->renumberCells(o2n->begin(),false);
1382 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1383 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
1384 if(f2->getTypeOfField()!=ON_NODES)
1386 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1387 DataArrayInt *part=0;
1388 bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
1389 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> partSafe(part);
1392 std::ostringstream oss; oss << "MEDLoader::WriteField : The file \""<< fileName << "\" already contains a mesh named \""<< f->getMesh()->getName() << "\" and this mesh in the file is not compatible (a subpart) with the mesh you intend to write ! This is maybe due to a too strict policy ! Try with to lease it by calling SetCompPolicyForCell !";
1393 throw INTERP_KERNEL::Exception(oss.str().c_str());
1395 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts=MEDFileField1TS::New();
1396 if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfCells())
1397 f1ts->setFieldNoProfileSBT(f2);
1400 part->setName(f1ts->createNewNameOfPfl().c_str());
1401 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1403 f1ts->write(fileName,0);
1408 DataArrayInt *part=0;
1409 bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
1410 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> partSafe(part);
1413 std::ostringstream oss; oss << "MEDLoader::WriteField : The file \""<< fileName << "\" already contains a mesh named \""<< f->getMesh()->getName() << "\" and this mesh in the file is not compatible (a subpart regarding nodes) with the mesh you intend to write ! This is maybe due to a too strict epsilon ! Try with to lease it by calling SetEpsilonForNodeComp !";
1414 throw INTERP_KERNEL::Exception(oss.str().c_str());
1416 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts=MEDFileField1TS::New();
1417 if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfNodes())
1418 f1ts->setFieldNoProfileSBT(f2);
1421 part->setName(f1ts->createNewNameOfPfl().c_str());
1422 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1424 f1ts->write(fileName,0);
1430 void MEDLoader::WriteFieldDep(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
1432 WriteField(fileName,f,writeFromScratch);
1435 void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception)
1438 throw INTERP_KERNEL::Exception("MEDLoader::WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1439 f->checkCoherency();
1440 int status=MEDLoaderBase::getStatusOfFile(fileName);
1441 if(status!=MEDLoaderBase::EXIST_RW)
1443 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1444 throw INTERP_KERNEL::Exception(oss.str().c_str());
1446 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts=MEDFileField1TS::New();
1447 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh()));
1449 throw INTERP_KERNEL::Exception("MEDLoader::WriteFieldUsingAlreadyWrittenMesh : only umesh in input field supported !");
1450 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1451 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1452 f2->renumberCells(o2n->begin(),false);
1453 f1ts->setFieldNoProfileSBT(f2);
1454 f1ts->write(fileName,0);