1 // Copyright (C) 2007-2020 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 "MEDCouplingFieldInt32.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;
149 INTERP_KERNEL::NormalizedCellType ConvertGeometryType(med_geometry_type geotype)
151 INTERP_KERNEL::NormalizedCellType result=INTERP_KERNEL::NORM_ERROR;
152 for(int i=0; i<MED_N_CELL_FIXED_GEO; i++)
154 if (typmai[i]==geotype)
164 * This method returns a first quick overview of mesh with name \a meshName into the file \a fileName.
165 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
166 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
168 int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities)
170 possibilities.clear();
171 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
174 char nommaa[MED_NAME_SIZE+1];
175 char maillage_description[MED_COMMENT_SIZE+1];
176 med_mesh_type type_maillage;
178 std::string trueMeshName;
179 int meshId=FromMedInt<int>(getIdFromMeshName(fid,meshName,trueMeshName));
180 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
181 med_sorting_type sortingType;
183 med_axis_type axisType;
184 med_int naxis(MEDmeshnAxis(fid,meshId));
185 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
186 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
187 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
191 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
195 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
197 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
199 med_geometry_type curMedType=typmai[i];
200 med_bool changement,transformation;
201 med_int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
202 med_int curNbOfElemF(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));//limitation
204 med_entity_type whichEntity;
205 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
208 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
209 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
216 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
217 possibilities.push_back(*it-ret);
224 int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName)
228 std::vector<std::string> meshes=getMeshNamesFid(fid);
230 throw INTERP_KERNEL::Exception("No mesh in file");
231 trueMeshName=meshes[0];
234 std::string meshNameStr(meshName);
235 std::vector<std::string> meshes=getMeshNamesFid(fid);
237 throw INTERP_KERNEL::Exception("No mesh in file");
238 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
239 if(iter==meshes.end())
241 std::ostringstream os2;
242 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
243 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
244 throw INTERP_KERNEL::Exception(os2.str().c_str());
246 trueMeshName=meshName;
247 return (int)( iter-meshes.begin()+1 );
250 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
252 med_mesh_type type_maillage;
253 char maillage_description[MED_COMMENT_SIZE+1];
254 char dtunit[MED_COMMENT_SIZE+1];
257 char nommaa[MED_NAME_SIZE+1];
258 med_axis_type axistype;
259 med_sorting_type stype;
260 med_int n=MEDnMesh(fid);
261 std::vector<std::string> ret(n);
264 med_int naxis(MEDmeshnAxis(fid,i+1));
265 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
266 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
268 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
269 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
276 * This methods allows to merger all entities and to considerate only cell types.
278 void MEDLoaderNS::dispatchElems(med_int nbOfElemCell, med_int nbOfElemFace, med_int& nbOfElem, med_entity_type& whichEntity)
280 if(nbOfElemCell>=nbOfElemFace)
282 whichEntity=MED_CELL;
283 nbOfElem=nbOfElemCell;
287 whichEntity=MED_CELL;
288 nbOfElem=nbOfElemFace;
294 void MEDCoupling::AssignStaticWritePropertiesTo(MEDCoupling::MEDFileWritable& obj)
296 obj.setTooLongStrPolicy(_TOO_LONG_STR);
299 bool MEDCoupling::HasXDR()
308 std::string MEDCoupling::MEDFileVersionStr()
312 std::fill(buf,buf+SZ,'\0');
313 const char START_EXPECTED[]="MED-";
314 med_err ret(MEDlibraryStrVersion(buf));
316 throw INTERP_KERNEL::Exception("MEDFileVersionStr : fail to find version of MED file ! It looks very bad !");
317 std::string zeRet(buf);
318 std::size_t pos(zeRet.find(START_EXPECTED,0));
321 std::ostringstream oss; oss << "MEDFileVersionStr : internal error ! The MEDFile returned version (\"" << zeRet << "\") has not the right pattern !";
322 throw INTERP_KERNEL::Exception(oss.str());
324 return zeRet.substr(sizeof(START_EXPECTED)-1,std::string::npos);
327 std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
329 #if MED_NUM_MAJEUR>3 || ( MED_NUM_MAJEUR==3 && ( (MED_NUM_MINEUR==2 && MED_NUM_RELEASE>=1) || MED_NUM_MINEUR>=3) )
330 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
332 const char START_EXPECTED[]="MED-";
334 std::fill(buf,buf+SZ,'\0');
335 MEDFILESAFECALLERRD0(MEDfileStrVersionRd,(fid,buf));
336 std::string ret(buf);
337 std::size_t pos(ret.find(START_EXPECTED,0));
340 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : internal error ! The MEDFile returned version (\"" << ret << "\") has not the right pattern !";
341 throw INTERP_KERNEL::Exception(oss.str());
343 return ret.substr(sizeof(START_EXPECTED)-1,std::string::npos);
345 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : is implemented with MEDFile " << MEDFileVersionStr() << " ! If you need this feature please use version >= 3.2.1.";
346 throw INTERP_KERNEL::Exception(oss.str());
350 void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
352 med_int majj,minn,rell;
353 med_err ret(MEDlibraryNumVersion(&majj,&minn,&rell));
355 throw INTERP_KERNEL::Exception("MEDFileVersion : fail to call MEDlibraryNumVersion ! It looks very bad !");
356 major=FromMedInt<int>(majj);
357 minor=FromMedInt<int>(minn);
358 release=FromMedInt<int>(rell);
362 * 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.
364 void MEDCoupling::SetEpsilonForNodeComp(double val)
366 _EPS_FOR_NODE_COMP=val;
370 * 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.
372 void MEDCoupling::SetCompPolicyForCell(int val)
378 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
379 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
381 void MEDCoupling::SetTooLongStrPolicy(int val)
387 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
388 * It returns, in this order :
389 * - 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...
390 * - the mesh dimension
391 * - the space dimension
392 * - the number of nodes
394 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)
396 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
398 char nommaa[MED_NAME_SIZE+1];
399 char maillage_description[MED_COMMENT_SIZE+1];
400 med_mesh_type type_maillage;
401 std::string trueMeshName;
402 int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
403 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
404 med_sorting_type sortingType;
405 med_int nstep, mDim, sDim;
406 med_axis_type axisType;
407 med_int naxis(MEDmeshnAxis(fid,meshId));
408 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
409 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
410 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&sDim,&mDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
411 meshDim=FromMedInt<int>(mDim);
412 spaceDim=FromMedInt<int>(sDim);
413 if(type_maillage!=MED_UNSTRUCTURED_MESH)
415 std::ostringstream oss; oss << "GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
416 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
417 throw INTERP_KERNEL::Exception(oss.str().c_str());
421 throw INTERP_KERNEL::Exception("GetUMeshGlobalInfo : multisteps on mesh not managed !");
424 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
426 std::vector<int> dims;
427 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
428 med_bool changement,transformation;
429 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
431 med_geometry_type curMedType=typmai[i];
432 med_int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
435 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
436 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
437 dims.push_back(mdimCell);
438 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
441 int maxLev=*std::max_element(dims.begin(),dims.end());
442 int lowLev=*std::min_element(dims.begin(),dims.end());
443 int nbOfLevels=maxLev-lowLev+1;
444 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
445 for(std::size_t i=0;i<dims.size();i++)
447 ret[maxLev-dims[i]].push_back(geoTypes[i]);
449 numberOfNodes=ToIdType(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
453 void MEDCoupling::CheckFileForRead(const std::string& fileName)
455 MEDFileUtilities::CheckFileForRead(fileName);
458 std::vector<std::string> MEDCoupling::GetMeshNames(const std::string& fileName)
460 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
461 return MEDLoaderNS::getMeshNamesFid(fid);
464 std::vector< std::pair<std::string,std::string> > MEDCoupling::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
466 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
467 med_int nbFields(MEDnField(fid));
468 std::vector<std::string> fields(nbFields);
469 med_field_type typcha;
470 for(int i=0;i<nbFields;i++)
472 med_int ncomp(MEDfieldnComponent(fid,i+1));
473 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
474 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
475 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
478 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
479 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
480 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
481 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
482 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
483 if(curFieldName==fieldName)
485 std::vector< std::pair<std::string,std::string> > ret(ncomp);
486 for(int j=0;j<ncomp;j++)
487 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
488 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
491 fields[i]=curFieldName;
493 std::ostringstream oss; oss << "GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
494 oss << "Possible field names are : " << std::endl;
495 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
496 throw INTERP_KERNEL::Exception(oss.str().c_str());
499 // see reference : https://en.cppreference.com/w/cpp/iterator/iterator
500 class MEDVectorStringIterator : public std::iterator< std::input_iterator_tag, long, long, const std::string*, std::string >
503 char *_data = nullptr;
505 explicit MEDVectorStringIterator(long num , char *data) : _num(num),_data(data) {}
506 MEDVectorStringIterator& operator++() { ++_num; return *this;}
507 bool operator==(const MEDVectorStringIterator& other) const {return _num == other._num;}
508 bool operator!=(const MEDVectorStringIterator& other) const {return !(*this == other);}
509 reference operator*() const {return MEDLoaderBase::buildStringFromFortran(_data+_num*MED_LNAME_SIZE,MED_LNAME_SIZE);}
512 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)
514 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
515 med_int nbFams(MEDnFamily(fid,meshName.c_str()));
516 char nomfam[MED_NAME_SIZE+1];
517 for(med_int i=0;i<nbFams;++i)
519 med_int nbGrps(MEDnFamilyGroup(fid,meshName.c_str(),i+1)),famId;
520 std::unique_ptr<char[]> gro{new char[MED_LNAME_SIZE*nbGrps+1]};
521 MEDFILESAFECALLERRD0(MEDfamilyInfo,(fid,meshName.c_str(),i+1,nomfam,&famId,gro.get()));
522 std::string fam(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE));
523 families[fam] = FromMedInt<mcIdType>(famId);
524 std::vector<std::string> v(nbGrps);
525 std::copy(MEDVectorStringIterator(0,gro.get()),MEDVectorStringIterator(nbGrps,gro.get()),v.begin());
526 groupsOnFam[fam] = v;
530 std::vector<std::string> MEDCoupling::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
532 std::vector<std::string> ret;
534 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
535 med_int nbFields=MEDnField(fid);
537 med_field_type typcha;
538 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
539 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
542 for(int i=0;i<nbFields;i++)
544 med_int ncomp(MEDfieldnComponent(fid,i+1));
545 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
546 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
548 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
549 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
550 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
551 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
552 if(curFieldName==fieldName)
553 ret.push_back(meshName);
558 std::vector<std::string> MEDCoupling::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
560 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
561 med_int nfam=MEDnFamily(fid,meshName.c_str());
562 std::vector<std::string> ret(nfam);
563 char nomfam[MED_NAME_SIZE+1];
565 for(int i=0;i<nfam;i++)
567 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
568 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
569 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
570 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
571 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
572 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
573 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
574 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
581 std::vector<std::string> MEDCoupling::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
583 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
584 med_int nfam=MEDnFamily(fid,meshName.c_str());
585 std::vector<std::string> ret;
586 char nomfam[MED_NAME_SIZE+1];
588 for(int i=0;i<nfam;i++)
590 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
591 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
592 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
593 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
594 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
595 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
596 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
597 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
598 for(int j=0;j<ngro;j++)
600 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
608 std::vector<std::string> MEDCoupling::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
610 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
611 med_int nfam(MEDnFamily(fid,meshName.c_str()));
612 std::vector<std::string> ret;
613 char nomfam[MED_NAME_SIZE+1];
616 for(int i=0;i<nfam && !found;i++)
618 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
619 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
620 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
621 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
622 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
623 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
624 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
625 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
626 found=(cur==famName);
628 for(int j=0;j<ngro;j++)
630 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
636 std::ostringstream oss;
637 oss << "GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
638 throw INTERP_KERNEL::Exception(oss.str().c_str());
644 std::vector<std::string> MEDCoupling::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
646 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
647 med_int nfam=MEDnFamily(fid,meshName.c_str());
648 std::vector<std::string> ret;
649 char nomfam[MED_NAME_SIZE+1];
651 for(int i=0;i<nfam;i++)
653 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
654 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
655 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
656 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
657 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
658 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
659 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
660 for(int j=0;j<ngro;j++)
662 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
663 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
670 std::vector<MEDCoupling::TypeOfField> MEDCoupling::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
672 std::vector<MEDCoupling::TypeOfField> ret;
673 MCAuto<MEDFileAnyTypeFieldMultiTS> fs(MEDFileAnyTypeFieldMultiTS::New(fileName,fieldName,false));
674 if(fs->getMeshName()!=meshName)
676 std::ostringstream oss; oss << "GetTypesOfField : The field \"" << fieldName << "\" in file \"" << fileName << "\" is not lying on mesh \"" << meshName << "\"";
677 oss << " The name of the mesh in file is \"" << fs->getMeshName() << "\"!";
678 throw INTERP_KERNEL::Exception(oss.str().c_str());
680 int nbTS(fs->getNumberOfTS());
683 for(int i=0;i<nbTS;i++)
685 MCAuto<MEDFileAnyTypeField1TS> f1ts(fs->getTimeStepAtPos(i));
686 std::vector<MEDCoupling::TypeOfField> tof(f1ts->getTypesOfFieldAvailable());
687 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=tof.begin();it!=tof.end();it++)
688 if(std::find(ret.begin(),ret.end(),*it)==ret.end())
691 // sort ret to put before ON_NODES then ON_CELLS then the remaining.
692 std::vector<MEDCoupling::TypeOfField> ret2;
693 if(std::find(ret.begin(),ret.end(),ON_NODES)!=ret.end())
694 ret2.push_back(ON_NODES);
695 if(std::find(ret.begin(),ret.end(),ON_CELLS)!=ret.end())
696 ret2.push_back(ON_CELLS);
697 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=ret.begin();it!=ret.end();it++)
698 if(*it!=ON_NODES && *it!=ON_CELLS)
703 std::vector<std::string> MEDCoupling::GetAllFieldNames(const std::string& fileName)
705 std::vector<std::string> ret;
706 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
707 med_int nbFields=MEDnField(fid);
708 med_field_type typcha;
709 for(int i=0;i<nbFields;i++)
711 med_int ncomp(MEDfieldnComponent(fid,i+1));
712 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
713 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
714 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
715 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
716 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
719 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
720 ret.push_back(std::string(nomcha));
725 std::vector<std::string> MEDCoupling::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
727 std::vector<std::string> ret;
728 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
729 med_int nbFields=MEDnField(fid);
731 med_field_type typcha;
732 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
733 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
735 for(int i=0;i<nbFields;i++)
737 med_int ncomp(MEDfieldnComponent(fid,i+1));
738 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
739 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
740 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
743 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
744 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
745 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
747 if(curMeshName==meshName)
748 ret.push_back(curFieldName);
755 std::vector<std::string> MEDCoupling::GetFieldNamesOnMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName)
757 MEDCoupling::CheckFileForRead(fileName);
761 return GetCellFieldNamesOnMesh(fileName,meshName);
763 return GetNodeFieldNamesOnMesh(fileName,meshName);
765 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
769 std::vector<std::string> MEDCoupling::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
771 std::vector<std::string> ret;
772 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
773 med_int nbFields=MEDnField(fid);
775 med_field_type typcha;
776 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
777 med_int numdt=0,numo=0;
779 char pflname[MED_NAME_SIZE+1]="";
780 char locname[MED_NAME_SIZE+1]="";
781 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
782 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
783 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
787 for(int i=0;i<nbFields;i++)
789 med_int ncomp(MEDfieldnComponent(fid,i+1));
790 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
791 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
792 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
793 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
794 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
795 med_int profilesize,nbi;
796 if(curMeshName==meshName)
799 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
803 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
804 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
805 pflname,&profilesize,locname,&nbi));
809 ret.push_back(curFieldName);
818 std::vector<std::string> MEDCoupling::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
820 std::vector<std::string> ret;
821 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
822 med_int nbFields=MEDnField(fid);
823 char pflname[MED_NAME_SIZE+1]="";
824 char locname[MED_NAME_SIZE+1]="";
826 med_field_type typcha;
827 med_int numdt=0,numo=0;
829 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
830 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
831 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
834 for(int i=0;i<nbFields;i++)
836 med_int ncomp(MEDfieldnComponent(fid,i+1));
837 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
838 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
840 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
841 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
842 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
845 med_int profilesize,nbi;
846 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
847 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
848 pflname,&profilesize,locname,&nbi));
849 if(curMeshName==meshName && nbOfVal>0)
851 ret.push_back(curFieldName);
858 std::vector< std::pair< std::pair<int,int>, double> > MEDCoupling::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
860 std::vector< std::pair< std::pair<int,int>, double > > ret;
861 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
862 med_int nbFields=MEDnField(fid);
864 med_field_type typcha;
865 med_int numdt=0,numo=0;
867 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
868 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
869 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
872 std::ostringstream oss; oss << "GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
873 for(int i=0;i<nbFields;i++)
875 med_int ncomp(MEDfieldnComponent(fid,i+1));
876 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
877 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
879 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
880 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
881 if(curFieldName==fieldName)
883 for(int k=0;k<nbPdt;k++)
885 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
886 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
892 oss << "\"" << curFieldName << "\"";
893 if(i!=nbFields-1) oss << ", ";
897 throw INTERP_KERNEL::Exception(oss.str().c_str());
900 double MEDCoupling::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
902 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
903 med_int nbFields=MEDnField(fid);
905 med_field_type typcha;
906 med_int numdt=0,numo=0;
909 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
910 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
911 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
915 double ret=std::numeric_limits<double>::max();
916 for(int i=0;i<nbFields && !found;i++)
918 med_int ncomp(MEDfieldnComponent(fid,i+1));
919 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
920 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
922 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt));
923 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
924 if(curFieldName==fieldName)
927 for(int k=0;k<nbPdt;k++)
929 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
930 if(numdt==iteration && numo==order)
938 if(!found || !found2)
940 std::ostringstream oss;
941 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
942 throw INTERP_KERNEL::Exception(oss.str().c_str());
947 std::vector< std::pair<int,int> > MEDCoupling::GetFieldIterations(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
949 MEDCoupling::CheckFileForRead(fileName);
953 return GetCellFieldIterations(fileName,meshName,fieldName);
955 return GetNodeFieldIterations(fileName,meshName,fieldName);
957 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
961 std::vector< std::pair<int,int> > MEDCoupling::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
963 std::string meshNameCpp(meshName);
964 std::vector< std::pair<int,int> > ret;
965 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
966 med_int nbFields=MEDnField(fid);
968 med_field_type typcha;
969 med_int numdt=0,numo=0;
971 char pflname[MED_NAME_SIZE+1]="";
972 char locname[MED_NAME_SIZE+1]="";
973 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
974 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
975 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
978 std::ostringstream oss; oss << "GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
979 std::set<std::string> s2;
980 for(int i=0;i<nbFields;i++)
982 med_int ncomp(MEDfieldnComponent(fid,i+1));
983 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
984 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
986 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
987 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
988 if(curFieldName==fieldName)
991 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
993 for(int k=0;k<nbPdt;k++)
995 med_int profilesize,nbi;
996 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
997 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
998 pflname,&profilesize,locname,&nbi));
999 std::string maa_ass_cpp(maa_ass);
1002 if(meshNameCpp==maa_ass_cpp)
1005 ret.push_back(std::make_pair(numdt,numo));
1008 s2.insert(maa_ass_cpp);
1015 oss << "\"" << curFieldName << "\"";
1016 if(i!=nbFields-1) oss << ", ";
1023 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1024 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1027 throw INTERP_KERNEL::Exception(oss.str().c_str());
1032 std::vector< std::pair<int,int> > MEDCoupling::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
1034 std::string meshNameCpp(meshName);
1035 std::vector< std::pair<int,int> > ret;
1036 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
1037 med_int nbFields=MEDnField(fid);
1039 med_field_type typcha;
1040 med_int numdt=0,numo=0;
1042 char pflname[MED_NAME_SIZE+1]="";
1043 char locname[MED_NAME_SIZE+1]="";
1044 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1045 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
1046 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1049 std::ostringstream oss; oss << "GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
1050 std::set<std::string> s2;
1051 for(int i=0;i<nbFields;i++)
1053 med_int ncomp(MEDfieldnComponent(fid,i+1));
1054 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
1055 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1057 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
1058 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1059 if(curFieldName==fieldName)
1061 for(int k=0;k<nbPdt;k++)
1063 med_int profilesize,nbi;
1064 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
1065 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1066 pflname,&profilesize,locname,&nbi));
1067 std::string maa_ass_cpp(maa_ass);
1070 if(meshNameCpp==maa_ass_cpp)
1071 { ret.push_back(std::make_pair(numdt,numo)); }
1073 s2.insert(maa_ass_cpp);
1079 oss << "\"" << curFieldName << "\"";
1080 if(i!=nbFields-1) oss << ", ";
1087 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1088 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1091 throw INTERP_KERNEL::Exception(oss.str().c_str());
1096 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1098 MEDCoupling::CheckFileForRead(fileName);
1099 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1100 MEDFileMesh *mmPtr(mm);
1101 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1103 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1104 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1107 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1108 return const_cast<MEDCouplingCMesh *>(ret);
1110 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1113 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1114 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1116 std::ostringstream oss; oss << "ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1117 throw INTERP_KERNEL::Exception(oss.str().c_str());
1120 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1122 MEDCoupling::CheckFileForRead(fileName);
1123 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1124 MEDFileMesh *mmPtr(mm);
1125 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1127 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1128 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1131 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1132 return const_cast<MEDCouplingCMesh *>(ret);
1134 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1137 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1138 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1140 std::ostringstream oss; oss << "ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1141 throw INTERP_KERNEL::Exception(oss.str().c_str());
1144 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1146 MEDCoupling::CheckFileForRead(fileName);
1147 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1148 MEDFileMesh *mmPtr(mm);
1149 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1152 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1153 throw INTERP_KERNEL::Exception(oss.str().c_str());
1155 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1158 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1160 MEDCoupling::CheckFileForRead(fileName);
1161 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1162 MEDFileMesh *mmPtr(mm);
1163 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1166 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1167 throw INTERP_KERNEL::Exception(oss.str().c_str());
1169 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1172 int MEDCoupling::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1174 MEDCoupling::CheckFileForRead(fileName);
1175 std::vector<int> poss;
1176 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1179 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
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 << "ReadUMeshFromFamilies : 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->getFamilies(meshDimRelToMax,fams,true);
1193 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1195 MEDCoupling::CheckFileForRead(fileName);
1196 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1197 MEDFileMesh *mmPtr(mm);
1198 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1201 std::ostringstream oss; oss << "ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1202 throw INTERP_KERNEL::Exception(oss.str().c_str());
1204 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1207 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName)
1209 std::vector<std::string> fieldNames(GetAllFieldNames(fileName));
1210 std::size_t sz(fieldNames.size());
1213 std::ostringstream oss;
1214 oss << "The file \"" << fileName << "\" contains no field !";
1215 throw INTERP_KERNEL::Exception(oss.str());
1219 std::ostringstream oss;
1220 oss << "In file \"" << fileName << "\" there are more than one field !" << std::endl;
1221 oss << "You are invited to use ReadField(fileName, fieldName) instead to avoid misleading concerning field you want to read !" << std::endl;
1222 oss << "For information, fields available are :" << std::endl;
1223 for(std::vector<std::string>::const_iterator it=fieldNames.begin();it!=fieldNames.end();it++)
1224 oss << " - \"" << *it << "\"" << std::endl;
1225 throw INTERP_KERNEL::Exception(oss.str());
1227 return ReadField(fileName,fieldNames[0]);
1230 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName)
1232 std::vector< std::pair< std::pair<int,int>, double> > iterations(GetAllFieldIterations(fileName,fieldName));
1233 std::size_t sz(iterations.size());
1236 std::ostringstream oss;
1237 oss << "In file \"" << fileName << "\" field \"" << fieldName << "\" exists but with no time steps !";
1238 throw INTERP_KERNEL::Exception(oss.str());
1242 std::ostringstream oss;
1243 oss << "In file \"" << fileName << "\" field \"" << fieldName << "\" exists but with more than one time steps !" << std::endl;
1244 oss << "You are invited to use ReadField(fileName, fieldName, iteration, order) instead to avoid misleading concerning time steps." << std::endl;
1245 oss << "For information, time steps available for field \"" << fieldName << "\" are :" << std::endl;
1246 for(std::vector< std::pair< std::pair<int,int>, double> >::const_iterator it=iterations.begin();it!=iterations.end();it++)
1247 oss << " - " << (*it).first.first << ", " << (*it).first.second << " (" << (*it).second << ")" << std::endl;
1248 throw INTERP_KERNEL::Exception(oss.str());
1250 return ReadField(fileName,fieldName,iterations[0].first.first,iterations[0].first.second);
1253 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order)
1255 MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
1256 MCAuto<MEDFileMesh> mesh(MEDFileMesh::New(fileName,f->getMeshName()));
1258 MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
1261 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(f1->field(mesh));
1262 return MEDCoupling::DynamicCast<MEDCouplingFieldDouble,MEDCouplingField>(ret);
1266 MCAuto<MEDFileInt32Field1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileInt32Field1TS>(f));
1269 MCAuto<MEDCoupling::MEDCouplingFieldInt32> ret(f1->field(mesh));
1270 return MEDCoupling::DynamicCast<MEDCouplingFieldInt32,MEDCouplingField>(ret);
1274 MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
1277 MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(f1->field(mesh));
1278 return MEDCoupling::DynamicCast<MEDCouplingFieldFloat,MEDCouplingField>(ret);
1281 throw INTERP_KERNEL::Exception("MEDCoupling::ReadField : only FLOAT32, FLOAT64 and INT32 supported for the moment !");
1284 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)
1286 MEDCoupling::CheckFileForRead(fileName);
1290 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1292 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1294 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1296 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1298 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1302 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsOnSameMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1303 const std::vector<std::pair<int,int> >& its)
1306 return std::vector<MEDCoupling::MEDCouplingFieldDouble *>();
1307 MEDCoupling::CheckFileForRead(fileName);
1308 std::vector<MEDCoupling::MEDCouplingFieldDouble *> ret(its.size());
1309 std::vector< MCAuto<MEDCouplingFieldDouble> > retSafe(its.size());
1312 //Retrieving mesh of rank 0 and field on rank 0 too.
1313 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1314 MEDFileMesh *mmPtr(mm);
1315 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1317 throw INTERP_KERNEL::Exception("ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1318 MCAuto<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1319 const DataArrayIdType *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1320 MCAuto<MEDCouplingUMesh> m2(m->clone(true));
1322 m2->renumberCells(o2n->begin(),true);
1324 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1326 MCAuto<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1327 MCAuto<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1329 retElt->renumberCells(o2n->begin(),true);
1330 retElt->setMesh(m2);
1334 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1335 ret[i]=retSafe[i].retn();
1339 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1340 const std::vector<std::pair<int,int> >& its)
1342 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1345 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1346 const std::vector<std::pair<int,int> >& its)
1348 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1351 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1352 const std::vector<std::pair<int,int> >& its)
1354 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1357 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1358 const std::vector<std::pair<int,int> >& its)
1360 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1363 namespace MEDCoupling
1366 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)
1368 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1369 MCAuto<MEDFileUMesh> muPtr(MEDCoupling::DynamicCast<MEDFileMesh,MEDFileUMesh>(mm));
1370 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1371 MCAuto<typename Traits<T>::FieldType> ret(ff->getFieldOnMeshAtLevel(type,m));
1372 if(muPtr.isNotNull())
1374 const DataArrayIdType *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1376 ret->renumberCells(num->begin());
1381 MEDCoupling::MEDCouplingField *ReadFieldCellLike(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1383 MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
1385 MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
1388 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(ReadFieldCellLikeT<double>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1393 MCAuto<MEDFileInt32Field1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileInt32Field1TS>(f));
1396 MCAuto<MEDCoupling::MEDCouplingFieldInt32> ret(ReadFieldCellLikeT<int>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1401 MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
1404 MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(ReadFieldCellLikeT<float>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1408 throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldCell : only FLOAT32, FLOAT64 and INT32 supported for the moment !");
1412 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)
1414 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1415 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1416 MCAuto<typename Traits<T>::FieldType> ret(ff->getFieldOnMeshAtLevel(ON_NODES,m));
1417 MCAuto<MEDFileUMesh> muPtr(MEDCoupling::DynamicCast<MEDFileMesh,MEDFileUMesh>(mm));
1418 if(ff->getPflsReallyUsed().empty())
1420 if(muPtr.isNotNull())
1422 const DataArrayIdType *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1424 ret->renumberCells(num->begin());
1429 DataArrayIdType *pfl(nullptr),*arr2(nullptr);
1430 MCAuto<typename Traits<T>::ArrayType> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl));
1431 MCAuto<DataArrayIdType> pflSafe(pfl);
1432 MCAuto<DataArrayIdType> mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end()));
1433 MCAuto<MEDCouplingUMesh> mzip(static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2)));
1434 MCAuto<DataArrayIdType> arr2Safe(arr2);
1435 MCAuto<DataArrayIdType> arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes()));
1436 MCAuto<DataArrayIdType> pflSorted(pflSafe->deepCopy()); pflSorted->sort(true);
1437 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1438 throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !");
1439 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1441 MCAuto<DataArrayIdType> o2n2(pflSafe->checkAndPreparePermutation());
1442 MCAuto<DataArrayIdType> n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples()));
1443 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1453 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1455 return ReadFieldCellLike(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1458 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1460 MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
1462 MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
1465 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(ReadFieldNodeT<double>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1470 MCAuto<MEDFileInt32Field1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileInt32Field1TS>(f));
1473 MCAuto<MEDCoupling::MEDCouplingFieldInt32> ret(ReadFieldNodeT<int>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1478 MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
1481 MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(ReadFieldNodeT<float>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1485 throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldNode : only FLOAT32, FLOAT64 and INT32 supported for the moment !");
1488 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1490 return ReadFieldCellLike(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1493 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1495 return ReadFieldCellLike(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1498 void MEDCoupling::WriteMesh(const std::string& fileName, const MEDCoupling::MEDCouplingMesh *mesh, bool writeFromScratch)
1501 throw INTERP_KERNEL::Exception("WriteMesh : input mesh is null !");
1502 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1505 WriteUMesh(fileName,um,writeFromScratch);
1508 int mod=writeFromScratch?2:0;
1509 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1512 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1513 AssignStaticWritePropertiesTo(*mmu);
1514 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1515 mmu->write(fileName,mod);
1518 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1521 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1522 AssignStaticWritePropertiesTo(*mmc);
1523 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1524 mmc->write(fileName,mod);
1527 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1530 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1531 AssignStaticWritePropertiesTo(*mmc);
1532 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1533 mmc->write(fileName,mod);
1536 throw INTERP_KERNEL::Exception("WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1539 void MEDCoupling::WriteUMesh(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1542 throw INTERP_KERNEL::Exception("WriteUMesh : input mesh is null !");
1543 int mod=writeFromScratch?2:0;
1544 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1545 AssignStaticWritePropertiesTo(*m);
1546 MCAuto<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCopy()));
1547 m->setMeshAtLevel(0,mcpy,true);
1548 m->write(fileName,mod);
1551 void MEDCoupling::WriteUMeshDep(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1553 WriteUMesh(fileName,mesh,writeFromScratch);
1556 void MEDCoupling::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1558 std::string meshName(meshNameC);
1559 if(meshName.empty())
1560 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 !");
1561 int status=MEDLoaderBase::getStatusOfFile(fileName);
1562 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1564 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1565 throw INTERP_KERNEL::Exception(oss.str().c_str());
1567 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1568 AssignStaticWritePropertiesTo(*m);
1569 m->setGroupsFromScratch(0,meshes,true);
1570 m->setName(meshNameC);
1571 int mod=writeFromScratch?2:0;
1572 m->write(fileName,mod);
1575 void MEDCoupling::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1577 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1580 void MEDCoupling::WriteUMeshes(const std::string& fileName, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1582 int mod(writeFromScratch?2:0);
1583 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1584 AssignStaticWritePropertiesTo(*m);
1585 m->setMeshes(meshes,true);
1586 m->write(fileName,mod);
1590 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f, bool writeFromScratch)
1592 MCAuto< typename MLFieldTraits<T>::F1TSType > ff(MLFieldTraits<T>::F1TSType::New());
1593 AssignStaticWritePropertiesTo(*ff);
1594 MCAuto<typename MEDCoupling::Traits<T>::FieldType> f2(f->deepCopy());
1595 const MEDCouplingMesh *m(f2->getMesh());
1596 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1597 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1598 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1599 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1600 MCAuto<MEDFileMesh> mm;
1601 int mod(writeFromScratch?2:0);
1604 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1605 AssignStaticWritePropertiesTo(*mmu);
1606 MCAuto<DataArrayIdType> o2n(um->getRenumArrForMEDFileFrmt());
1607 MCAuto<DataArrayIdType> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1608 f2->renumberCells(o2n->begin(),false);
1609 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1610 mmu->setRenumFieldArr(0,n2o);
1611 ff->setFieldNoProfileSBT(f2);
1612 mmu->write(fileName,mod);
1616 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1617 AssignStaticWritePropertiesTo(*mmu);
1618 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1619 ff->setFieldNoProfileSBT(f2);
1620 mmu->write(fileName,mod);
1624 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1625 AssignStaticWritePropertiesTo(*mmc);
1626 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1627 ff->setFieldNoProfileSBT(f2);
1628 mmc->write(fileName,mod);
1632 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1633 AssignStaticWritePropertiesTo(*mmc);
1634 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1635 ff->setFieldNoProfileSBT(f2);
1636 mmc->write(fileName,mod);
1639 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1640 ff->write(fileName,0);
1644 void WriteFieldT(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f, bool writeFromScratch)
1647 throw INTERP_KERNEL::Exception("WriteField : input field is NULL !");
1648 f->checkConsistencyLight();
1649 int status(MEDLoaderBase::getStatusOfFile(fileName));
1650 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1652 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1653 throw INTERP_KERNEL::Exception(oss.str().c_str());
1655 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1657 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile<T>(fileName,f,true);
1661 std::vector<std::string> meshNames(GetMeshNames(fileName));
1663 throw INTERP_KERNEL::Exception("WriteField : trying to write a field with no mesh !");
1664 std::string fileNameCpp(f->getMesh()->getName());
1665 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1666 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile<T>(fileName,f,false);
1669 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1670 AssignStaticWritePropertiesTo(*mm);
1671 const MEDFileMesh *mmPtr(mm);
1672 const MEDFileUMesh *mmuPtr(dynamic_cast<const MEDFileUMesh *>(mmPtr));
1674 throw INTERP_KERNEL::Exception("WriteField : only umeshes are supported now !");
1675 MCAuto< typename MEDCoupling::Traits<T>::FieldType > f2(f->deepCopy());
1676 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh())));
1678 throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !");
1679 MCAuto<DataArrayIdType> o2n(m->getRenumArrForMEDFileFrmt());
1680 f2->renumberCells(o2n->begin(),false);
1681 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1682 MCAuto<MEDCouplingUMesh> mread(mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension()));
1683 if(f2->getTypeOfField()!=ON_NODES)
1685 if(!m->getCoords()->isEqualWithoutConsideringStr(*mread->getCoords(),_EPS_FOR_NODE_COMP))
1686 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1688 mread->setCoords(m->getCoords());
1689 DataArrayIdType *part(NULL);
1690 bool b(mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part));
1691 MCAuto<DataArrayIdType> partSafe(part);
1694 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 !";
1695 throw INTERP_KERNEL::Exception(oss.str().c_str());
1697 MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
1698 AssignStaticWritePropertiesTo(*f1ts);
1699 if(part->isIota(mread->getNumberOfCells()))
1700 f1ts->setFieldNoProfileSBT(f2);
1703 part->setName(f1ts->createNewNameOfPfl().c_str());
1704 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1706 f1ts->write(fileName,0);
1711 DataArrayIdType *part(NULL);
1712 bool b(mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part));
1713 MCAuto<DataArrayIdType> partSafe(part);
1716 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 !";
1717 throw INTERP_KERNEL::Exception(oss.str().c_str());
1719 MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
1720 AssignStaticWritePropertiesTo(*f1ts);
1721 if(part->isIota(mread->getNumberOfNodes()))
1722 f1ts->setFieldNoProfileSBT(f2);
1725 part->setName(f1ts->createNewNameOfPfl().c_str());
1726 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1728 f1ts->write(fileName,0);
1734 void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch)
1737 throw INTERP_KERNEL::Exception("WriteField : input field is null !");
1739 const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldDouble *>(f));
1742 WriteFieldT<double>(fileName,f1,writeFromScratch);
1747 const MEDCoupling::MEDCouplingFieldInt32 *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt32 *>(f));
1750 WriteFieldT<int>(fileName,f1,writeFromScratch);
1755 const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldFloat *>(f));
1758 WriteFieldT<float>(fileName,f1,writeFromScratch);
1762 throw INTERP_KERNEL::Exception("WriteField : input field is not in FLOAT32, FLOAT64, INT32 !");
1765 void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch)
1767 WriteField(fileName,f,writeFromScratch);
1771 void WriteFieldUsingAlreadyWrittenMeshT(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f)
1774 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMeshT : input field is null !");
1775 f->checkConsistencyLight();
1776 int status(MEDLoaderBase::getStatusOfFile(fileName));
1777 if(status!=MEDLoaderBase::EXIST_RW)
1779 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1780 throw INTERP_KERNEL::Exception(oss.str().c_str());
1782 MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
1783 AssignStaticWritePropertiesTo(*f1ts);
1784 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1787 MCAuto<DataArrayIdType> o2n(m->getRenumArrForMEDFileFrmt());
1788 MCAuto< typename MEDCoupling::Traits<T>::FieldType > f2(f->deepCopy());
1789 f2->renumberCells(o2n->begin(),false);
1790 f1ts->setFieldNoProfileSBT(f2);
1793 f1ts->setFieldNoProfileSBT(f);
1794 f1ts->write(fileName,0);
1797 void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingField *f)
1800 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1802 const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldDouble *>(f));
1804 WriteFieldUsingAlreadyWrittenMeshT<double>(fileName,f1);
1808 const MEDCoupling::MEDCouplingFieldInt32 *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt32 *>(f));
1810 WriteFieldUsingAlreadyWrittenMeshT<int>(fileName,f1);
1814 const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldFloat *>(f));
1816 WriteFieldUsingAlreadyWrittenMeshT<float>(fileName,f1);
1819 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is not in FLOAT32, FLOAT64, INT32 !");