1 // Copyright (C) 2007-2019 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, or (at your option) any later version.
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 "MEDLoaderNS.hxx"
25 #include "MEDFileSafeCaller.txx"
26 #include "MEDFileMesh.hxx"
27 #include "MEDFileField.hxx"
28 #include "CellModel.hxx"
29 #include "MEDCouplingUMesh.hxx"
30 #include "MEDCouplingMemArray.hxx"
31 #include "MEDCouplingFieldDouble.hxx"
32 #include "MEDCouplingFieldFloat.hxx"
33 #include "MEDCouplingFieldInt.hxx"
34 #include "MEDCouplingGaussLocalization.hxx"
35 #include "MEDCouplingTraits.hxx"
38 #include "InterpKernelAutoPtr.hxx"
52 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
77 med_geometry_type typmainoeud[1] = { MED_NONE };
79 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
80 INTERP_KERNEL::NORM_SEG2,
81 INTERP_KERNEL::NORM_SEG3,
82 INTERP_KERNEL::NORM_SEG4,
83 INTERP_KERNEL::NORM_TRI3,
84 INTERP_KERNEL::NORM_QUAD4,
85 INTERP_KERNEL::NORM_TRI6,
86 INTERP_KERNEL::NORM_TRI7,
87 INTERP_KERNEL::NORM_QUAD8,
88 INTERP_KERNEL::NORM_QUAD9,
89 INTERP_KERNEL::NORM_TETRA4,
90 INTERP_KERNEL::NORM_PYRA5,
91 INTERP_KERNEL::NORM_PENTA6,
92 INTERP_KERNEL::NORM_HEXA8,
93 INTERP_KERNEL::NORM_HEXGP12,
94 INTERP_KERNEL::NORM_TETRA10,
95 INTERP_KERNEL::NORM_PYRA13,
96 INTERP_KERNEL::NORM_PENTA15,
97 INTERP_KERNEL::NORM_PENTA18,
98 INTERP_KERNEL::NORM_HEXA20,
99 INTERP_KERNEL::NORM_HEXA27,
100 INTERP_KERNEL::NORM_POLYGON,
101 INTERP_KERNEL::NORM_QPOLYG,
102 INTERP_KERNEL::NORM_POLYHED };
104 med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE] = { MED_POINT1,//0
139 double _EPS_FOR_NODE_COMP=1.e-12;
141 int _COMP_FOR_CELL=0;
145 using namespace MEDCoupling;
150 * This method returns a first quick overview of mesh with name \a meshName into the file \a fileName.
151 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
152 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
154 int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities)
156 possibilities.clear();
157 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
160 char nommaa[MED_NAME_SIZE+1];
161 char maillage_description[MED_COMMENT_SIZE+1];
162 med_mesh_type type_maillage;
164 std::string trueMeshName;
165 int meshId=FromMedInt<int>(getIdFromMeshName(fid,meshName,trueMeshName));
166 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
167 med_sorting_type sortingType;
169 med_axis_type axisType;
170 med_int naxis(MEDmeshnAxis(fid,meshId));
171 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
172 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
173 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
177 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
181 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
183 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
185 med_geometry_type curMedType=typmai[i];
186 med_bool changement,transformation;
187 med_int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
188 med_int curNbOfElemF(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));//limitation
190 med_entity_type whichEntity;
191 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
194 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
195 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
202 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
203 possibilities.push_back(*it-ret);
210 int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName)
214 std::vector<std::string> meshes=getMeshNamesFid(fid);
216 throw INTERP_KERNEL::Exception("No mesh in file");
217 trueMeshName=meshes[0];
220 std::string meshNameStr(meshName);
221 std::vector<std::string> meshes=getMeshNamesFid(fid);
223 throw INTERP_KERNEL::Exception("No mesh in file");
224 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
225 if(iter==meshes.end())
227 std::ostringstream os2;
228 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
229 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
230 throw INTERP_KERNEL::Exception(os2.str().c_str());
232 trueMeshName=meshName;
233 return (int)( iter-meshes.begin()+1 );
236 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
238 med_mesh_type type_maillage;
239 char maillage_description[MED_COMMENT_SIZE+1];
240 char dtunit[MED_COMMENT_SIZE+1];
243 char nommaa[MED_NAME_SIZE+1];
244 med_axis_type axistype;
245 med_sorting_type stype;
246 med_int n=MEDnMesh(fid);
247 std::vector<std::string> ret(n);
250 med_int naxis(MEDmeshnAxis(fid,i+1));
251 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
252 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
254 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
255 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
262 * This methods allows to merger all entities and to considerate only cell types.
264 void MEDLoaderNS::dispatchElems(med_int nbOfElemCell, med_int nbOfElemFace, med_int& nbOfElem, med_entity_type& whichEntity)
266 if(nbOfElemCell>=nbOfElemFace)
268 whichEntity=MED_CELL;
269 nbOfElem=nbOfElemCell;
273 whichEntity=MED_CELL;
274 nbOfElem=nbOfElemFace;
280 void MEDCoupling::AssignStaticWritePropertiesTo(MEDCoupling::MEDFileWritable& obj)
282 obj.setTooLongStrPolicy(_TOO_LONG_STR);
285 bool MEDCoupling::HasXDR()
294 std::string MEDCoupling::MEDFileVersionStr()
298 std::fill(buf,buf+SZ,'\0');
299 const char START_EXPECTED[]="MED-";
300 med_err ret(MEDlibraryStrVersion(buf));
302 throw INTERP_KERNEL::Exception("MEDFileVersionStr : fail to find version of MED file ! It looks very bad !");
303 std::string zeRet(buf);
304 std::size_t pos(zeRet.find(START_EXPECTED,0));
307 std::ostringstream oss; oss << "MEDFileVersionStr : internal error ! The MEDFile returned version (\"" << zeRet << "\") has not the right pattern !";
308 throw INTERP_KERNEL::Exception(oss.str());
310 return zeRet.substr(sizeof(START_EXPECTED)-1,std::string::npos);
313 std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
315 #if MED_NUM_MAJEUR>3 || ( MED_NUM_MAJEUR==3 && ( (MED_NUM_MINEUR==2 && MED_NUM_RELEASE>=1) || MED_NUM_MINEUR>=3) )
316 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
318 const char START_EXPECTED[]="MED-";
320 std::fill(buf,buf+SZ,'\0');
321 MEDFILESAFECALLERRD0(MEDfileStrVersionRd,(fid,buf));
322 std::string ret(buf);
323 std::size_t pos(ret.find(START_EXPECTED,0));
326 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : internal error ! The MEDFile returned version (\"" << ret << "\") has not the right pattern !";
327 throw INTERP_KERNEL::Exception(oss.str());
329 return ret.substr(sizeof(START_EXPECTED)-1,std::string::npos);
331 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : is implemented with MEDFile " << MEDFileVersionStr() << " ! If you need this feature please use version >= 3.2.1.";
332 throw INTERP_KERNEL::Exception(oss.str());
336 void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
338 med_int majj,minn,rell;
339 med_err ret(MEDlibraryNumVersion(&majj,&minn,&rell));
341 throw INTERP_KERNEL::Exception("MEDFileVersion : fail to call MEDlibraryNumVersion ! It looks very bad !");
342 major=FromMedInt<int>(majj);
343 minor=FromMedInt<int>(minn);
344 release=FromMedInt<int>(rell);
348 * This method sets the epsilon value used for node comparison when trying to build a profile for a field on node/cell on an already written mesh.
350 void MEDCoupling::SetEpsilonForNodeComp(double val)
352 _EPS_FOR_NODE_COMP=val;
356 * 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.
358 void MEDCoupling::SetCompPolicyForCell(int val)
364 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
365 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
367 void MEDCoupling::SetTooLongStrPolicy(int val)
373 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
374 * It returns, in this order :
375 * - 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...
376 * - the mesh dimension
377 * - the space dimension
378 * - the number of nodes
380 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > MEDCoupling::GetUMeshGlobalInfo(const std::string& fileName, const std::string& meshName, int &meshDim, int& spaceDim, mcIdType& numberOfNodes)
382 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
384 char nommaa[MED_NAME_SIZE+1];
385 char maillage_description[MED_COMMENT_SIZE+1];
386 med_mesh_type type_maillage;
387 std::string trueMeshName;
388 int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
389 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
390 med_sorting_type sortingType;
391 med_int nstep, mDim, sDim;
392 med_axis_type axisType;
393 med_int naxis(MEDmeshnAxis(fid,meshId));
394 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
395 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
396 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&sDim,&mDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
397 meshDim=FromMedInt<int>(mDim);
398 spaceDim=FromMedInt<int>(sDim);
399 if(type_maillage!=MED_UNSTRUCTURED_MESH)
401 std::ostringstream oss; oss << "GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
402 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
403 throw INTERP_KERNEL::Exception(oss.str().c_str());
407 throw INTERP_KERNEL::Exception("GetUMeshGlobalInfo : multisteps on mesh not managed !");
410 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
412 std::vector<int> dims;
413 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
414 med_bool changement,transformation;
415 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
417 med_geometry_type curMedType=typmai[i];
418 med_int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
421 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
422 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
423 dims.push_back(mdimCell);
424 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
427 int maxLev=*std::max_element(dims.begin(),dims.end());
428 int lowLev=*std::min_element(dims.begin(),dims.end());
429 int nbOfLevels=maxLev-lowLev+1;
430 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
431 for(std::size_t i=0;i<dims.size();i++)
433 ret[maxLev-dims[i]].push_back(geoTypes[i]);
435 numberOfNodes=ToIdType(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
439 void MEDCoupling::CheckFileForRead(const std::string& fileName)
441 MEDFileUtilities::CheckFileForRead(fileName);
444 std::vector<std::string> MEDCoupling::GetMeshNames(const std::string& fileName)
446 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
447 return MEDLoaderNS::getMeshNamesFid(fid);
450 std::vector< std::pair<std::string,std::string> > MEDCoupling::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
452 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
453 med_int nbFields(MEDnField(fid));
454 std::vector<std::string> fields(nbFields);
455 med_field_type typcha;
456 for(int i=0;i<nbFields;i++)
458 med_int ncomp(MEDfieldnComponent(fid,i+1));
459 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
460 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
461 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
464 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
465 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
466 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
467 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
468 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
469 if(curFieldName==fieldName)
471 std::vector< std::pair<std::string,std::string> > ret(ncomp);
472 for(int j=0;j<ncomp;j++)
473 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
474 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
477 fields[i]=curFieldName;
479 std::ostringstream oss; oss << "GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
480 oss << "Possible field names are : " << std::endl;
481 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
482 throw INTERP_KERNEL::Exception(oss.str().c_str());
485 // see reference : https://en.cppreference.com/w/cpp/iterator/iterator
486 class MEDVectorStringIterator : public std::iterator< std::input_iterator_tag, long, long, const std::string*, std::string >
489 char *_data = nullptr;
491 explicit MEDVectorStringIterator(long num , char *data) : _num(num),_data(data) {}
492 MEDVectorStringIterator& operator++() { ++_num; return *this;}
493 bool operator==(const MEDVectorStringIterator& other) const {return _num == other._num;}
494 bool operator!=(const MEDVectorStringIterator& other) const {return !(*this == other);}
495 reference operator*() const {return MEDLoaderBase::buildStringFromFortran(_data+_num*MED_LNAME_SIZE,MED_LNAME_SIZE);}
498 void MEDCoupling::GetFamiliesGroupsInfo(const std::string& fileName, const std::string& meshName, std::map<std::string,mcIdType>& families, std::map<std::string,std::vector<std::string>>& groupsOnFam)
500 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
501 med_int nbFams(MEDnFamily(fid,meshName.c_str()));
502 char nomfam[MED_NAME_SIZE+1];
503 for(med_int i=0;i<nbFams;++i)
505 med_int nbGrps(MEDnFamilyGroup(fid,meshName.c_str(),i+1)),famId;
506 std::unique_ptr<char[]> gro{new char[MED_LNAME_SIZE*nbGrps+1]};
507 MEDFILESAFECALLERRD0(MEDfamilyInfo,(fid,meshName.c_str(),i+1,nomfam,&famId,gro.get()));
508 std::string fam(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE));
509 families[fam] = FromMedInt<mcIdType>(famId);
510 std::vector<std::string> v(nbGrps);
511 std::copy(MEDVectorStringIterator(0,gro.get()),MEDVectorStringIterator(nbGrps,gro.get()),v.begin());
512 groupsOnFam[fam] = v;
516 std::vector<std::string> MEDCoupling::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
518 std::vector<std::string> ret;
520 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
521 med_int nbFields=MEDnField(fid);
523 med_field_type typcha;
524 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
525 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
528 for(int i=0;i<nbFields;i++)
530 med_int ncomp(MEDfieldnComponent(fid,i+1));
531 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
532 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
534 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
535 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
536 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
537 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
538 if(curFieldName==fieldName)
539 ret.push_back(meshName);
544 std::vector<std::string> MEDCoupling::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
546 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
547 med_int nfam=MEDnFamily(fid,meshName.c_str());
548 std::vector<std::string> ret(nfam);
549 char nomfam[MED_NAME_SIZE+1];
551 for(int i=0;i<nfam;i++)
553 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
554 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),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.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
560 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
567 std::vector<std::string> MEDCoupling::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
569 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
570 med_int nfam=MEDnFamily(fid,meshName.c_str());
571 std::vector<std::string> ret;
572 char nomfam[MED_NAME_SIZE+1];
574 for(int i=0;i<nfam;i++)
576 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
577 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
578 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
579 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
580 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
581 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
582 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
583 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
584 for(int j=0;j<ngro;j++)
586 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
594 std::vector<std::string> MEDCoupling::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
596 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
597 med_int nfam(MEDnFamily(fid,meshName.c_str()));
598 std::vector<std::string> ret;
599 char nomfam[MED_NAME_SIZE+1];
602 for(int i=0;i<nfam && !found;i++)
604 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
605 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
606 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
607 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
608 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
609 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
610 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
611 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
612 found=(cur==famName);
614 for(int j=0;j<ngro;j++)
616 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
622 std::ostringstream oss;
623 oss << "GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
624 throw INTERP_KERNEL::Exception(oss.str().c_str());
630 std::vector<std::string> MEDCoupling::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
632 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
633 med_int nfam=MEDnFamily(fid,meshName.c_str());
634 std::vector<std::string> ret;
635 char nomfam[MED_NAME_SIZE+1];
637 for(int i=0;i<nfam;i++)
639 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
640 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
641 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
642 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
643 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
644 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
645 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
646 for(int j=0;j<ngro;j++)
648 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
649 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
656 std::vector<MEDCoupling::TypeOfField> MEDCoupling::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
658 std::vector<MEDCoupling::TypeOfField> ret;
659 MCAuto<MEDFileAnyTypeFieldMultiTS> fs(MEDFileAnyTypeFieldMultiTS::New(fileName,fieldName,false));
660 if(fs->getMeshName()!=meshName)
662 std::ostringstream oss; oss << "GetTypesOfField : The field \"" << fieldName << "\" in file \"" << fileName << "\" is not lying on mesh \"" << meshName << "\"";
663 oss << " The name of the mesh in file is \"" << fs->getMeshName() << "\"!";
664 throw INTERP_KERNEL::Exception(oss.str().c_str());
666 int nbTS(fs->getNumberOfTS());
669 for(int i=0;i<nbTS;i++)
671 MCAuto<MEDFileAnyTypeField1TS> f1ts(fs->getTimeStepAtPos(i));
672 std::vector<MEDCoupling::TypeOfField> tof(f1ts->getTypesOfFieldAvailable());
673 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=tof.begin();it!=tof.end();it++)
674 if(std::find(ret.begin(),ret.end(),*it)==ret.end())
677 // sort ret to put before ON_NODES then ON_CELLS then the remaining.
678 std::vector<MEDCoupling::TypeOfField> ret2;
679 if(std::find(ret.begin(),ret.end(),ON_NODES)!=ret.end())
680 ret2.push_back(ON_NODES);
681 if(std::find(ret.begin(),ret.end(),ON_CELLS)!=ret.end())
682 ret2.push_back(ON_CELLS);
683 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=ret.begin();it!=ret.end();it++)
684 if(*it!=ON_NODES && *it!=ON_CELLS)
689 std::vector<std::string> MEDCoupling::GetAllFieldNames(const std::string& fileName)
691 std::vector<std::string> ret;
692 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
693 med_int nbFields=MEDnField(fid);
694 med_field_type typcha;
695 for(int i=0;i<nbFields;i++)
697 med_int ncomp(MEDfieldnComponent(fid,i+1));
698 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
699 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
700 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
701 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
702 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
705 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
706 ret.push_back(std::string(nomcha));
711 std::vector<std::string> MEDCoupling::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
713 std::vector<std::string> ret;
714 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
715 med_int nbFields=MEDnField(fid);
717 med_field_type typcha;
718 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
719 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
721 for(int i=0;i<nbFields;i++)
723 med_int ncomp(MEDfieldnComponent(fid,i+1));
724 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
725 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
726 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
729 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
730 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
731 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
733 if(curMeshName==meshName)
734 ret.push_back(curFieldName);
741 std::vector<std::string> MEDCoupling::GetFieldNamesOnMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName)
743 MEDCoupling::CheckFileForRead(fileName);
747 return GetCellFieldNamesOnMesh(fileName,meshName);
749 return GetNodeFieldNamesOnMesh(fileName,meshName);
751 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
755 std::vector<std::string> MEDCoupling::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
757 std::vector<std::string> ret;
758 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
759 med_int nbFields=MEDnField(fid);
761 med_field_type typcha;
762 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
763 med_int numdt=0,numo=0;
765 char pflname[MED_NAME_SIZE+1]="";
766 char locname[MED_NAME_SIZE+1]="";
767 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
768 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
769 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
773 for(int i=0;i<nbFields;i++)
775 med_int ncomp(MEDfieldnComponent(fid,i+1));
776 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
777 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
778 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
779 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
780 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
781 med_int profilesize,nbi;
782 if(curMeshName==meshName)
785 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
789 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
790 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
791 pflname,&profilesize,locname,&nbi));
795 ret.push_back(curFieldName);
804 std::vector<std::string> MEDCoupling::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
806 std::vector<std::string> ret;
807 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
808 med_int nbFields=MEDnField(fid);
809 char pflname[MED_NAME_SIZE+1]="";
810 char locname[MED_NAME_SIZE+1]="";
812 med_field_type typcha;
813 med_int numdt=0,numo=0;
815 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
816 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
817 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
820 for(int i=0;i<nbFields;i++)
822 med_int ncomp(MEDfieldnComponent(fid,i+1));
823 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
824 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
826 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
827 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
828 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
831 med_int profilesize,nbi;
832 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
833 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
834 pflname,&profilesize,locname,&nbi));
835 if(curMeshName==meshName && nbOfVal>0)
837 ret.push_back(curFieldName);
844 std::vector< std::pair< std::pair<int,int>, double> > MEDCoupling::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
846 std::vector< std::pair< std::pair<int,int>, double > > ret;
847 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
848 med_int nbFields=MEDnField(fid);
850 med_field_type typcha;
851 med_int numdt=0,numo=0;
853 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
854 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
855 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
858 std::ostringstream oss; oss << "GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
859 for(int i=0;i<nbFields;i++)
861 med_int ncomp(MEDfieldnComponent(fid,i+1));
862 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
863 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
865 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
866 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
867 if(curFieldName==fieldName)
869 for(int k=0;k<nbPdt;k++)
871 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
872 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
878 oss << "\"" << curFieldName << "\"";
879 if(i!=nbFields-1) oss << ", ";
883 throw INTERP_KERNEL::Exception(oss.str().c_str());
886 double MEDCoupling::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
888 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
889 med_int nbFields=MEDnField(fid);
891 med_field_type typcha;
892 med_int numdt=0,numo=0;
895 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
896 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
897 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
901 double ret=std::numeric_limits<double>::max();
902 for(int i=0;i<nbFields && !found;i++)
904 med_int ncomp(MEDfieldnComponent(fid,i+1));
905 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
906 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
908 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt));
909 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
910 if(curFieldName==fieldName)
913 for(int k=0;k<nbPdt;k++)
915 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
916 if(numdt==iteration && numo==order)
924 if(!found || !found2)
926 std::ostringstream oss;
927 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
928 throw INTERP_KERNEL::Exception(oss.str().c_str());
933 std::vector< std::pair<int,int> > MEDCoupling::GetFieldIterations(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
935 MEDCoupling::CheckFileForRead(fileName);
939 return GetCellFieldIterations(fileName,meshName,fieldName);
941 return GetNodeFieldIterations(fileName,meshName,fieldName);
943 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
947 std::vector< std::pair<int,int> > MEDCoupling::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
949 std::string meshNameCpp(meshName);
950 std::vector< std::pair<int,int> > ret;
951 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
952 med_int nbFields=MEDnField(fid);
954 med_field_type typcha;
955 med_int numdt=0,numo=0;
957 char pflname[MED_NAME_SIZE+1]="";
958 char locname[MED_NAME_SIZE+1]="";
959 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
960 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
961 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
964 std::ostringstream oss; oss << "GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
965 std::set<std::string> s2;
966 for(int i=0;i<nbFields;i++)
968 med_int ncomp(MEDfieldnComponent(fid,i+1));
969 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
970 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
972 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
973 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
974 if(curFieldName==fieldName)
977 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
979 for(int k=0;k<nbPdt;k++)
981 med_int profilesize,nbi;
982 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
983 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
984 pflname,&profilesize,locname,&nbi));
985 std::string maa_ass_cpp(maa_ass);
988 if(meshNameCpp==maa_ass_cpp)
991 ret.push_back(std::make_pair(numdt,numo));
994 s2.insert(maa_ass_cpp);
1001 oss << "\"" << curFieldName << "\"";
1002 if(i!=nbFields-1) oss << ", ";
1009 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1010 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1013 throw INTERP_KERNEL::Exception(oss.str().c_str());
1018 std::vector< std::pair<int,int> > MEDCoupling::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
1020 std::string meshNameCpp(meshName);
1021 std::vector< std::pair<int,int> > ret;
1022 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
1023 med_int nbFields=MEDnField(fid);
1025 med_field_type typcha;
1026 med_int numdt=0,numo=0;
1028 char pflname[MED_NAME_SIZE+1]="";
1029 char locname[MED_NAME_SIZE+1]="";
1030 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1031 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
1032 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1035 std::ostringstream oss; oss << "GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
1036 std::set<std::string> s2;
1037 for(int i=0;i<nbFields;i++)
1039 med_int ncomp(MEDfieldnComponent(fid,i+1));
1040 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
1041 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1043 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
1044 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1045 if(curFieldName==fieldName)
1047 for(int k=0;k<nbPdt;k++)
1049 med_int profilesize,nbi;
1050 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
1051 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1052 pflname,&profilesize,locname,&nbi));
1053 std::string maa_ass_cpp(maa_ass);
1056 if(meshNameCpp==maa_ass_cpp)
1057 { ret.push_back(std::make_pair(numdt,numo)); }
1059 s2.insert(maa_ass_cpp);
1065 oss << "\"" << curFieldName << "\"";
1066 if(i!=nbFields-1) oss << ", ";
1073 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1074 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1077 throw INTERP_KERNEL::Exception(oss.str().c_str());
1082 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1084 MEDCoupling::CheckFileForRead(fileName);
1085 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1086 MEDFileMesh *mmPtr(mm);
1087 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1089 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1090 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1093 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1094 return const_cast<MEDCouplingCMesh *>(ret);
1096 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1099 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1100 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1102 std::ostringstream oss; oss << "ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1103 throw INTERP_KERNEL::Exception(oss.str().c_str());
1106 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1108 MEDCoupling::CheckFileForRead(fileName);
1109 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1110 MEDFileMesh *mmPtr(mm);
1111 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1113 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1114 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1117 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1118 return const_cast<MEDCouplingCMesh *>(ret);
1120 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1123 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1124 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1126 std::ostringstream oss; oss << "ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1127 throw INTERP_KERNEL::Exception(oss.str().c_str());
1130 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1132 MEDCoupling::CheckFileForRead(fileName);
1133 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1134 MEDFileMesh *mmPtr(mm);
1135 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1138 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1139 throw INTERP_KERNEL::Exception(oss.str().c_str());
1141 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1144 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1146 MEDCoupling::CheckFileForRead(fileName);
1147 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1148 MEDFileMesh *mmPtr(mm);
1149 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1152 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1153 throw INTERP_KERNEL::Exception(oss.str().c_str());
1155 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1158 int MEDCoupling::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1160 MEDCoupling::CheckFileForRead(fileName);
1161 std::vector<int> poss;
1162 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1165 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1167 MEDCoupling::CheckFileForRead(fileName);
1168 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1169 MEDFileMesh *mmPtr(mm);
1170 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1173 std::ostringstream oss; oss << "ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1174 throw INTERP_KERNEL::Exception(oss.str().c_str());
1176 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1179 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1181 MEDCoupling::CheckFileForRead(fileName);
1182 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1183 MEDFileMesh *mmPtr(mm);
1184 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1187 std::ostringstream oss; oss << "ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1188 throw INTERP_KERNEL::Exception(oss.str().c_str());
1190 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1193 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName)
1195 std::vector<std::string> fieldNames(GetAllFieldNames(fileName));
1196 std::size_t sz(fieldNames.size());
1199 std::ostringstream oss;
1200 oss << "The file \"" << fileName << "\" contains no field !";
1201 throw INTERP_KERNEL::Exception(oss.str());
1205 std::ostringstream oss;
1206 oss << "In file \"" << fileName << "\" there are more than one field !" << std::endl;
1207 oss << "You are invited to use ReadField(fileName, fieldName) instead to avoid misleading concerning field you want to read !" << std::endl;
1208 oss << "For information, fields available are :" << std::endl;
1209 for(std::vector<std::string>::const_iterator it=fieldNames.begin();it!=fieldNames.end();it++)
1210 oss << " - \"" << *it << "\"" << std::endl;
1211 throw INTERP_KERNEL::Exception(oss.str());
1213 return ReadField(fileName,fieldNames[0]);
1216 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName)
1218 std::vector< std::pair< std::pair<int,int>, double> > iterations(GetAllFieldIterations(fileName,fieldName));
1219 std::size_t sz(iterations.size());
1222 std::ostringstream oss;
1223 oss << "In file \"" << fileName << "\" field \"" << fieldName << "\" exists but with no time steps !";
1224 throw INTERP_KERNEL::Exception(oss.str());
1228 std::ostringstream oss;
1229 oss << "In file \"" << fileName << "\" field \"" << fieldName << "\" exists but with more than one time steps !" << std::endl;
1230 oss << "You are invited to use ReadField(fileName, fieldName, iteration, order) instead to avoid misleading concerning time steps." << std::endl;
1231 oss << "For information, time steps available for field \"" << fieldName << "\" are :" << std::endl;
1232 for(std::vector< std::pair< std::pair<int,int>, double> >::const_iterator it=iterations.begin();it!=iterations.end();it++)
1233 oss << " - " << (*it).first.first << ", " << (*it).first.second << " (" << (*it).second << ")" << std::endl;
1234 throw INTERP_KERNEL::Exception(oss.str());
1236 return ReadField(fileName,fieldName,iterations[0].first.first,iterations[0].first.second);
1239 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order)
1241 MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
1242 MCAuto<MEDFileMesh> mesh(MEDFileMesh::New(fileName,f->getMeshName()));
1244 MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
1247 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(f1->field(mesh));
1248 return MEDCoupling::DynamicCast<MEDCouplingFieldDouble,MEDCouplingField>(ret);
1252 MCAuto<MEDFileIntField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileIntField1TS>(f));
1255 MCAuto<MEDCoupling::MEDCouplingFieldInt> ret(f1->field(mesh));
1256 return MEDCoupling::DynamicCast<MEDCouplingFieldInt,MEDCouplingField>(ret);
1260 MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
1263 MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(f1->field(mesh));
1264 return MEDCoupling::DynamicCast<MEDCouplingFieldFloat,MEDCouplingField>(ret);
1267 throw INTERP_KERNEL::Exception("MEDCoupling::ReadField : only FLOAT32, FLOAT64 and INT32 supported for the moment !");
1270 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1272 MEDCoupling::CheckFileForRead(fileName);
1276 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1278 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1280 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1282 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1284 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1288 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsOnSameMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1289 const std::vector<std::pair<int,int> >& its)
1292 return std::vector<MEDCoupling::MEDCouplingFieldDouble *>();
1293 MEDCoupling::CheckFileForRead(fileName);
1294 std::vector<MEDCoupling::MEDCouplingFieldDouble *> ret(its.size());
1295 std::vector< MCAuto<MEDCouplingFieldDouble> > retSafe(its.size());
1298 //Retrieving mesh of rank 0 and field on rank 0 too.
1299 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1300 MEDFileMesh *mmPtr(mm);
1301 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1303 throw INTERP_KERNEL::Exception("ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1304 MCAuto<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1305 const DataArrayIdType *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1306 MCAuto<MEDCouplingUMesh> m2(m->clone(true));
1308 m2->renumberCells(o2n->begin(),true);
1310 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1312 MCAuto<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1313 MCAuto<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1315 retElt->renumberCells(o2n->begin(),true);
1316 retElt->setMesh(m2);
1320 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1321 ret[i]=retSafe[i].retn();
1325 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1326 const std::vector<std::pair<int,int> >& its)
1328 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1331 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1332 const std::vector<std::pair<int,int> >& its)
1334 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1337 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1338 const std::vector<std::pair<int,int> >& its)
1340 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1343 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1344 const std::vector<std::pair<int,int> >& its)
1346 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1349 namespace MEDCoupling
1352 MCAuto<typename Traits<T>::FieldType> ReadFieldCellLikeT(typename MLFieldTraits<T>::F1TSType *ff, MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1354 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1355 MCAuto<MEDFileUMesh> muPtr(MEDCoupling::DynamicCast<MEDFileMesh,MEDFileUMesh>(mm));
1356 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1357 MCAuto<typename Traits<T>::FieldType> ret(ff->getFieldOnMeshAtLevel(type,m));
1358 if(muPtr.isNotNull())
1360 const DataArrayIdType *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1362 ret->renumberCells(num->begin());
1367 MEDCoupling::MEDCouplingField *ReadFieldCellLike(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1369 MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
1371 MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
1374 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(ReadFieldCellLikeT<double>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1379 MCAuto<MEDFileIntField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileIntField1TS>(f));
1382 MCAuto<MEDCoupling::MEDCouplingFieldInt> ret(ReadFieldCellLikeT<int>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1387 MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
1390 MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(ReadFieldCellLikeT<float>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1394 throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldCell : only FLOAT32, FLOAT64 and INT32 supported for the moment !");
1398 MCAuto<typename Traits<T>::FieldType> ReadFieldNodeT(typename MLFieldTraits<T>::F1TSType *ff, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1400 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1401 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1402 MCAuto<typename Traits<T>::FieldType> ret(ff->getFieldOnMeshAtLevel(ON_NODES,m));
1403 MCAuto<MEDFileUMesh> muPtr(MEDCoupling::DynamicCast<MEDFileMesh,MEDFileUMesh>(mm));
1404 if(ff->getPflsReallyUsed().empty())
1406 if(muPtr.isNotNull())
1408 const DataArrayIdType *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1410 ret->renumberCells(num->begin());
1415 DataArrayIdType *pfl(nullptr),*arr2(nullptr);
1416 MCAuto<typename Traits<T>::ArrayType> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl));
1417 MCAuto<DataArrayIdType> pflSafe(pfl);
1418 MCAuto<DataArrayIdType> mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end()));
1419 MCAuto<MEDCouplingUMesh> mzip(static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2)));
1420 MCAuto<DataArrayIdType> arr2Safe(arr2);
1421 MCAuto<DataArrayIdType> arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes()));
1422 MCAuto<DataArrayIdType> pflSorted(pflSafe->deepCopy()); pflSorted->sort(true);
1423 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1424 throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !");
1425 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1427 MCAuto<DataArrayIdType> o2n2(pflSafe->checkAndPreparePermutation());
1428 MCAuto<DataArrayIdType> n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples()));
1429 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1439 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1441 return ReadFieldCellLike(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1444 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1446 MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
1448 MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
1451 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(ReadFieldNodeT<double>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1456 MCAuto<MEDFileIntField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileIntField1TS>(f));
1459 MCAuto<MEDCoupling::MEDCouplingFieldInt> ret(ReadFieldNodeT<int>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1464 MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
1467 MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(ReadFieldNodeT<float>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1471 throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldNode : only FLOAT32, FLOAT64 and INT32 supported for the moment !");
1474 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1476 return ReadFieldCellLike(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1479 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1481 return ReadFieldCellLike(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1484 void MEDCoupling::WriteMesh(const std::string& fileName, const MEDCoupling::MEDCouplingMesh *mesh, bool writeFromScratch)
1487 throw INTERP_KERNEL::Exception("WriteMesh : input mesh is null !");
1488 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1491 WriteUMesh(fileName,um,writeFromScratch);
1494 int mod=writeFromScratch?2:0;
1495 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1498 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1499 AssignStaticWritePropertiesTo(*mmu);
1500 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1501 mmu->write(fileName,mod);
1504 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1507 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1508 AssignStaticWritePropertiesTo(*mmc);
1509 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1510 mmc->write(fileName,mod);
1513 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1516 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1517 AssignStaticWritePropertiesTo(*mmc);
1518 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1519 mmc->write(fileName,mod);
1522 throw INTERP_KERNEL::Exception("WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1525 void MEDCoupling::WriteUMesh(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1528 throw INTERP_KERNEL::Exception("WriteUMesh : input mesh is null !");
1529 int mod=writeFromScratch?2:0;
1530 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1531 AssignStaticWritePropertiesTo(*m);
1532 MCAuto<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCopy()));
1533 m->setMeshAtLevel(0,mcpy,true);
1534 m->write(fileName,mod);
1537 void MEDCoupling::WriteUMeshDep(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1539 WriteUMesh(fileName,mesh,writeFromScratch);
1542 void MEDCoupling::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1544 std::string meshName(meshNameC);
1545 if(meshName.empty())
1546 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 !");
1547 int status=MEDLoaderBase::getStatusOfFile(fileName);
1548 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1550 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1551 throw INTERP_KERNEL::Exception(oss.str().c_str());
1553 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1554 AssignStaticWritePropertiesTo(*m);
1555 m->setGroupsFromScratch(0,meshes,true);
1556 m->setName(meshNameC);
1557 int mod=writeFromScratch?2:0;
1558 m->write(fileName,mod);
1561 void MEDCoupling::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1563 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1566 void MEDCoupling::WriteUMeshes(const std::string& fileName, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1568 int mod(writeFromScratch?2:0);
1569 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1570 AssignStaticWritePropertiesTo(*m);
1571 m->setMeshes(meshes,true);
1572 m->write(fileName,mod);
1576 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f, bool writeFromScratch)
1578 MCAuto< typename MLFieldTraits<T>::F1TSType > ff(MLFieldTraits<T>::F1TSType::New());
1579 AssignStaticWritePropertiesTo(*ff);
1580 MCAuto<typename MEDCoupling::Traits<T>::FieldType> f2(f->deepCopy());
1581 const MEDCouplingMesh *m(f2->getMesh());
1582 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1583 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1584 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1585 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1586 MCAuto<MEDFileMesh> mm;
1587 int mod(writeFromScratch?2:0);
1590 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1591 AssignStaticWritePropertiesTo(*mmu);
1592 MCAuto<DataArrayIdType> o2n(um->getRenumArrForMEDFileFrmt());
1593 MCAuto<DataArrayIdType> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1594 f2->renumberCells(o2n->begin(),false);
1595 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1596 mmu->setRenumFieldArr(0,n2o);
1597 ff->setFieldNoProfileSBT(f2);
1598 mmu->write(fileName,mod);
1602 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1603 AssignStaticWritePropertiesTo(*mmu);
1604 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1605 ff->setFieldNoProfileSBT(f2);
1606 mmu->write(fileName,mod);
1610 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1611 AssignStaticWritePropertiesTo(*mmc);
1612 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1613 ff->setFieldNoProfileSBT(f2);
1614 mmc->write(fileName,mod);
1618 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1619 AssignStaticWritePropertiesTo(*mmc);
1620 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1621 ff->setFieldNoProfileSBT(f2);
1622 mmc->write(fileName,mod);
1625 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1626 ff->write(fileName,0);
1630 void WriteFieldT(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f, bool writeFromScratch)
1633 throw INTERP_KERNEL::Exception("WriteField : input field is NULL !");
1634 f->checkConsistencyLight();
1635 int status(MEDLoaderBase::getStatusOfFile(fileName));
1636 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1638 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1639 throw INTERP_KERNEL::Exception(oss.str().c_str());
1641 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1643 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile<T>(fileName,f,true);
1647 std::vector<std::string> meshNames(GetMeshNames(fileName));
1649 throw INTERP_KERNEL::Exception("WriteField : trying to write a field with no mesh !");
1650 std::string fileNameCpp(f->getMesh()->getName());
1651 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1652 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile<T>(fileName,f,false);
1655 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1656 AssignStaticWritePropertiesTo(*mm);
1657 const MEDFileMesh *mmPtr(mm);
1658 const MEDFileUMesh *mmuPtr(dynamic_cast<const MEDFileUMesh *>(mmPtr));
1660 throw INTERP_KERNEL::Exception("WriteField : only umeshes are supported now !");
1661 MCAuto< typename MEDCoupling::Traits<T>::FieldType > f2(f->deepCopy());
1662 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh())));
1664 throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !");
1665 MCAuto<DataArrayIdType> o2n(m->getRenumArrForMEDFileFrmt());
1666 f2->renumberCells(o2n->begin(),false);
1667 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1668 MCAuto<MEDCouplingUMesh> mread(mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension()));
1669 if(f2->getTypeOfField()!=ON_NODES)
1671 if(!m->getCoords()->isEqualWithoutConsideringStr(*mread->getCoords(),_EPS_FOR_NODE_COMP))
1672 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1674 mread->setCoords(m->getCoords());
1675 DataArrayIdType *part(NULL);
1676 bool b(mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part));
1677 MCAuto<DataArrayIdType> partSafe(part);
1680 std::ostringstream oss; oss << "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 !";
1681 throw INTERP_KERNEL::Exception(oss.str().c_str());
1683 MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
1684 AssignStaticWritePropertiesTo(*f1ts);
1685 if(part->isIota(mread->getNumberOfCells()))
1686 f1ts->setFieldNoProfileSBT(f2);
1689 part->setName(f1ts->createNewNameOfPfl().c_str());
1690 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1692 f1ts->write(fileName,0);
1697 DataArrayIdType *part(NULL);
1698 bool b(mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part));
1699 MCAuto<DataArrayIdType> partSafe(part);
1702 std::ostringstream oss; oss << "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 !";
1703 throw INTERP_KERNEL::Exception(oss.str().c_str());
1705 MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
1706 AssignStaticWritePropertiesTo(*f1ts);
1707 if(part->isIota(mread->getNumberOfNodes()))
1708 f1ts->setFieldNoProfileSBT(f2);
1711 part->setName(f1ts->createNewNameOfPfl().c_str());
1712 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1714 f1ts->write(fileName,0);
1720 void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch)
1723 throw INTERP_KERNEL::Exception("WriteField : input field is null !");
1725 const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldDouble *>(f));
1728 WriteFieldT<double>(fileName,f1,writeFromScratch);
1733 const MEDCoupling::MEDCouplingFieldInt *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt *>(f));
1736 WriteFieldT<int>(fileName,f1,writeFromScratch);
1741 const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldFloat *>(f));
1744 WriteFieldT<float>(fileName,f1,writeFromScratch);
1748 throw INTERP_KERNEL::Exception("WriteField : input field is not in FLOAT32, FLOAT64, INT32 !");
1751 void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch)
1753 WriteField(fileName,f,writeFromScratch);
1757 void WriteFieldUsingAlreadyWrittenMeshT(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f)
1760 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMeshT : input field is null !");
1761 f->checkConsistencyLight();
1762 int status(MEDLoaderBase::getStatusOfFile(fileName));
1763 if(status!=MEDLoaderBase::EXIST_RW)
1765 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1766 throw INTERP_KERNEL::Exception(oss.str().c_str());
1768 MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
1769 AssignStaticWritePropertiesTo(*f1ts);
1770 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1773 MCAuto<DataArrayIdType> o2n(m->getRenumArrForMEDFileFrmt());
1774 MCAuto< typename MEDCoupling::Traits<T>::FieldType > f2(f->deepCopy());
1775 f2->renumberCells(o2n->begin(),false);
1776 f1ts->setFieldNoProfileSBT(f2);
1779 f1ts->setFieldNoProfileSBT(f);
1780 f1ts->write(fileName,0);
1783 void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingField *f)
1786 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1788 const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldDouble *>(f));
1790 WriteFieldUsingAlreadyWrittenMeshT<double>(fileName,f1);
1794 const MEDCoupling::MEDCouplingFieldInt *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt *>(f));
1796 WriteFieldUsingAlreadyWrittenMeshT<int>(fileName,f1);
1800 const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldFloat *>(f));
1802 WriteFieldUsingAlreadyWrittenMeshT<float>(fileName,f1);
1805 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is not in FLOAT32, FLOAT64, INT32 !");