1 // Copyright (C) 2007-2021 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 "MEDCouplingFieldInt64.hxx"
35 #include "MEDCouplingGaussLocalization.hxx"
36 #include "MEDCouplingTraits.hxx"
39 #include "InterpKernelAutoPtr.hxx"
53 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
54 extern med_geometry_type typmainoeud[1];
55 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
56 extern med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE];
59 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
84 med_geometry_type typmainoeud[1] = { MED_NONE };
86 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
87 INTERP_KERNEL::NORM_SEG2,
88 INTERP_KERNEL::NORM_SEG3,
89 INTERP_KERNEL::NORM_SEG4,
90 INTERP_KERNEL::NORM_TRI3,
91 INTERP_KERNEL::NORM_QUAD4,
92 INTERP_KERNEL::NORM_TRI6,
93 INTERP_KERNEL::NORM_TRI7,
94 INTERP_KERNEL::NORM_QUAD8,
95 INTERP_KERNEL::NORM_QUAD9,
96 INTERP_KERNEL::NORM_TETRA4,
97 INTERP_KERNEL::NORM_PYRA5,
98 INTERP_KERNEL::NORM_PENTA6,
99 INTERP_KERNEL::NORM_HEXA8,
100 INTERP_KERNEL::NORM_HEXGP12,
101 INTERP_KERNEL::NORM_TETRA10,
102 INTERP_KERNEL::NORM_PYRA13,
103 INTERP_KERNEL::NORM_PENTA15,
104 INTERP_KERNEL::NORM_PENTA18,
105 INTERP_KERNEL::NORM_HEXA20,
106 INTERP_KERNEL::NORM_HEXA27,
107 INTERP_KERNEL::NORM_POLYGON,
108 INTERP_KERNEL::NORM_QPOLYG,
109 INTERP_KERNEL::NORM_POLYHED };
111 med_geometry_type typmai3[INTERP_KERNEL::NORM_MAXTYPE] = { MED_POINT1,//0
146 // Just for this translation unit:
147 static double _EPS_FOR_NODE_COMP=1.e-12;
148 static int _COMP_FOR_CELL=0;
149 static int _TOO_LONG_STR=0;
152 using namespace MEDCoupling;
156 INTERP_KERNEL::NormalizedCellType ConvertGeometryType(med_geometry_type geotype)
158 INTERP_KERNEL::NormalizedCellType result=INTERP_KERNEL::NORM_ERROR;
159 for(int i=0; i<MED_N_CELL_FIXED_GEO; i++)
161 if (typmai[i]==geotype)
171 * This method returns a first quick overview of mesh with name \a meshName into the file \a fileName.
172 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
173 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
175 int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities)
177 possibilities.clear();
178 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
181 char nommaa[MED_NAME_SIZE+1];
182 char maillage_description[MED_COMMENT_SIZE+1];
183 med_mesh_type type_maillage;
185 std::string trueMeshName;
186 int meshId=FromMedInt<int>(getIdFromMeshName(fid,meshName,trueMeshName));
187 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
188 med_sorting_type sortingType;
190 med_axis_type axisType;
191 med_int naxis(MEDmeshnAxis(fid,meshId));
192 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
193 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
194 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
198 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
202 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
204 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
206 med_geometry_type curMedType=typmai[i];
207 med_bool changement,transformation;
208 med_int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
209 med_int curNbOfElemF(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));//limitation
211 med_entity_type whichEntity;
212 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
215 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
216 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
223 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
224 possibilities.push_back(*it-ret);
231 int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName)
235 std::vector<std::string> meshes=getMeshNamesFid(fid);
237 throw INTERP_KERNEL::Exception("No mesh in file");
238 trueMeshName=meshes[0];
241 std::string meshNameStr(meshName);
242 std::vector<std::string> meshes=getMeshNamesFid(fid);
244 throw INTERP_KERNEL::Exception("No mesh in file");
245 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
246 if(iter==meshes.end())
248 std::ostringstream os2;
249 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
250 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
251 throw INTERP_KERNEL::Exception(os2.str().c_str());
253 trueMeshName=meshName;
254 return (int)( iter-meshes.begin()+1 );
257 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
259 med_mesh_type type_maillage;
260 char maillage_description[MED_COMMENT_SIZE+1];
261 char dtunit[MED_COMMENT_SIZE+1];
264 char nommaa[MED_NAME_SIZE+1];
265 med_axis_type axistype;
266 med_sorting_type stype;
267 med_int n=MEDnMesh(fid);
268 std::vector<std::string> ret(n);
271 med_int naxis(MEDmeshnAxis(fid,i+1));
272 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
273 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
275 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
276 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
283 * This methods allows to merger all entities and to considerate only cell types.
285 void MEDLoaderNS::dispatchElems(med_int nbOfElemCell, med_int nbOfElemFace, med_int& nbOfElem, med_entity_type& whichEntity)
287 if(nbOfElemCell>=nbOfElemFace)
289 whichEntity=MED_CELL;
290 nbOfElem=nbOfElemCell;
294 whichEntity=MED_CELL;
295 nbOfElem=nbOfElemFace;
301 void MEDCoupling::AssignStaticWritePropertiesTo(MEDCoupling::MEDFileWritable& obj)
303 obj.setTooLongStrPolicy(_TOO_LONG_STR);
306 bool MEDCoupling::HasXDR()
315 std::string MEDCoupling::MEDFileVersionStr()
319 std::fill(buf,buf+SZ,'\0');
320 const char START_EXPECTED[]="MED-";
321 med_err ret(MEDlibraryStrVersion(buf));
323 throw INTERP_KERNEL::Exception("MEDFileVersionStr : fail to find version of MED file ! It looks very bad !");
324 std::string zeRet(buf);
325 std::size_t pos(zeRet.find(START_EXPECTED,0));
328 std::ostringstream oss; oss << "MEDFileVersionStr : internal error ! The MEDFile returned version (\"" << zeRet << "\") has not the right pattern !";
329 throw INTERP_KERNEL::Exception(oss.str());
331 return zeRet.substr(sizeof(START_EXPECTED)-1,std::string::npos);
334 std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
336 #if MED_NUM_MAJEUR>3 || ( MED_NUM_MAJEUR==3 && ( (MED_NUM_MINEUR==2 && MED_NUM_RELEASE>=1) || MED_NUM_MINEUR>=3) )
337 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
339 const char START_EXPECTED[]="MED-";
341 std::fill(buf,buf+SZ,'\0');
342 MEDFILESAFECALLERRD0(MEDfileStrVersionRd,(fid,buf));
343 std::string ret(buf);
344 std::size_t pos(ret.find(START_EXPECTED,0));
347 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : internal error ! The MEDFile returned version (\"" << ret << "\") has not the right pattern !";
348 throw INTERP_KERNEL::Exception(oss.str());
350 return ret.substr(sizeof(START_EXPECTED)-1,std::string::npos);
352 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : is implemented with MEDFile " << MEDFileVersionStr() << " ! If you need this feature please use version >= 3.2.1.";
353 throw INTERP_KERNEL::Exception(oss.str());
357 void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
359 med_int majj,minn,rell;
360 med_err ret(MEDlibraryNumVersion(&majj,&minn,&rell));
362 throw INTERP_KERNEL::Exception("MEDFileVersion : fail to call MEDlibraryNumVersion ! It looks very bad !");
363 major=FromMedInt<int>(majj);
364 minor=FromMedInt<int>(minn);
365 release=FromMedInt<int>(rell);
369 * 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.
371 void MEDCoupling::SetEpsilonForNodeComp(double val)
373 _EPS_FOR_NODE_COMP=val;
377 * 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.
379 void MEDCoupling::SetCompPolicyForCell(int val)
385 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
386 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
388 void MEDCoupling::SetTooLongStrPolicy(int val)
394 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
395 * It returns, in this order :
396 * - 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...
397 * - the mesh dimension
398 * - the space dimension
399 * - the number of nodes
401 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)
403 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
405 char nommaa[MED_NAME_SIZE+1];
406 char maillage_description[MED_COMMENT_SIZE+1];
407 med_mesh_type type_maillage;
408 std::string trueMeshName;
409 int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
410 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
411 med_sorting_type sortingType;
412 med_int nstep, mDim, sDim;
413 med_axis_type axisType;
414 med_int naxis(MEDmeshnAxis(fid,meshId));
415 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
416 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
417 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&sDim,&mDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
418 meshDim=FromMedInt<int>(mDim);
419 spaceDim=FromMedInt<int>(sDim);
420 if(type_maillage!=MED_UNSTRUCTURED_MESH)
422 std::ostringstream oss; oss << "GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
423 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
424 throw INTERP_KERNEL::Exception(oss.str().c_str());
428 throw INTERP_KERNEL::Exception("GetUMeshGlobalInfo : multisteps on mesh not managed !");
431 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
433 std::vector<int> dims;
434 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
435 med_bool changement,transformation;
436 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
438 med_geometry_type curMedType=typmai[i];
439 med_int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
442 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
443 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
444 dims.push_back(mdimCell);
445 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
448 int maxLev=*std::max_element(dims.begin(),dims.end());
449 int lowLev=*std::min_element(dims.begin(),dims.end());
450 int nbOfLevels=maxLev-lowLev+1;
451 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
452 for(std::size_t i=0;i<dims.size();i++)
454 ret[maxLev-dims[i]].push_back(geoTypes[i]);
456 numberOfNodes=ToIdType(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
460 void MEDCoupling::CheckFileForRead(const std::string& fileName)
462 MEDFileUtilities::CheckFileForRead(fileName);
465 std::vector<std::string> MEDCoupling::GetMeshNames(const std::string& fileName)
467 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
468 return MEDLoaderNS::getMeshNamesFid(fid);
471 std::vector< std::pair<std::string,std::string> > MEDCoupling::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
473 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
474 med_int nbFields(MEDnField(fid));
475 std::vector<std::string> fields(nbFields);
476 med_field_type typcha;
477 for(int i=0;i<nbFields;i++)
479 med_int ncomp(MEDfieldnComponent(fid,i+1));
480 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
481 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
482 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
485 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
486 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
487 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
488 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
489 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
490 if(curFieldName==fieldName)
492 std::vector< std::pair<std::string,std::string> > ret(ncomp);
493 for(int j=0;j<ncomp;j++)
494 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
495 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
498 fields[i]=curFieldName;
500 std::ostringstream oss; oss << "GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
501 oss << "Possible field names are : " << std::endl;
502 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
503 throw INTERP_KERNEL::Exception(oss.str().c_str());
506 // see reference : https://en.cppreference.com/w/cpp/iterator/iterator
507 class MEDVectorStringIterator : public std::iterator< std::input_iterator_tag, long, long, const std::string*, std::string >
510 char *_data = nullptr;
512 explicit MEDVectorStringIterator(long num , char *data) : _num(num),_data(data) {}
513 MEDVectorStringIterator& operator++() { ++_num; return *this;}
514 bool operator==(const MEDVectorStringIterator& other) const {return _num == other._num;}
515 bool operator!=(const MEDVectorStringIterator& other) const {return !(*this == other);}
516 reference operator*() const {return MEDLoaderBase::buildStringFromFortran(_data+_num*MED_LNAME_SIZE,MED_LNAME_SIZE);}
519 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)
521 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
522 med_int nbFams(MEDnFamily(fid,meshName.c_str()));
523 char nomfam[MED_NAME_SIZE+1];
524 for(med_int i=0;i<nbFams;++i)
526 med_int nbGrps(MEDnFamilyGroup(fid,meshName.c_str(),FromMedInt<int>(i+1))),famId;
527 std::unique_ptr<char[]> gro{new char[MED_LNAME_SIZE*nbGrps+1]};
528 MEDFILESAFECALLERRD0(MEDfamilyInfo,(fid,meshName.c_str(),FromMedInt<int>(i+1),nomfam,&famId,gro.get()));
529 std::string fam(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE));
530 families[fam] = FromMedInt<mcIdType>(famId);
531 std::vector<std::string> v(nbGrps);
532 std::copy(MEDVectorStringIterator(0,gro.get()),MEDVectorStringIterator(nbGrps,gro.get()),v.begin());
533 groupsOnFam[fam] = v;
537 std::vector<std::string> MEDCoupling::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
539 std::vector<std::string> ret;
541 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
542 med_int nbFields=MEDnField(fid);
544 med_field_type typcha;
545 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
546 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
549 for(int i=0;i<nbFields;i++)
551 med_int ncomp(MEDfieldnComponent(fid,i+1));
552 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
553 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
555 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
556 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
557 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
558 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
559 if(curFieldName==fieldName)
560 ret.push_back(meshName);
565 std::vector<std::string> MEDCoupling::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
567 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
568 med_int nfam=MEDnFamily(fid,meshName.c_str());
569 std::vector<std::string> ret(nfam);
570 char nomfam[MED_NAME_SIZE+1];
572 for(int i=0;i<nfam;i++)
574 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
575 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
576 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
577 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
578 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
579 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
580 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
581 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
588 std::vector<std::string> MEDCoupling::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
590 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
591 med_int nfam=MEDnFamily(fid,meshName.c_str());
592 std::vector<std::string> ret;
593 char nomfam[MED_NAME_SIZE+1];
595 for(int i=0;i<nfam;i++)
597 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
598 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
599 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
600 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
601 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
602 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
603 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
604 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
605 for(int j=0;j<ngro;j++)
607 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
615 std::vector<std::string> MEDCoupling::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
617 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
618 med_int nfam(MEDnFamily(fid,meshName.c_str()));
619 std::vector<std::string> ret;
620 char nomfam[MED_NAME_SIZE+1];
623 for(int i=0;i<nfam && !found;i++)
625 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
626 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
627 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
628 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
629 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
630 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
631 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
632 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
633 found=(cur==famName);
635 for(int j=0;j<ngro;j++)
637 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
643 std::ostringstream oss;
644 oss << "GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
645 throw INTERP_KERNEL::Exception(oss.str().c_str());
651 std::vector<std::string> MEDCoupling::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
653 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
654 med_int nfam=MEDnFamily(fid,meshName.c_str());
655 std::vector<std::string> ret;
656 char nomfam[MED_NAME_SIZE+1];
658 for(int i=0;i<nfam;i++)
660 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
661 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
662 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
663 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
664 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
665 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
666 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
667 for(int j=0;j<ngro;j++)
669 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
670 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
677 std::vector<MEDCoupling::TypeOfField> MEDCoupling::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
679 std::vector<MEDCoupling::TypeOfField> ret;
680 MCAuto<MEDFileAnyTypeFieldMultiTS> fs(MEDFileAnyTypeFieldMultiTS::New(fileName,fieldName,false));
681 if(fs->getMeshName()!=meshName)
683 std::ostringstream oss; oss << "GetTypesOfField : The field \"" << fieldName << "\" in file \"" << fileName << "\" is not lying on mesh \"" << meshName << "\"";
684 oss << " The name of the mesh in file is \"" << fs->getMeshName() << "\"!";
685 throw INTERP_KERNEL::Exception(oss.str().c_str());
687 int nbTS(fs->getNumberOfTS());
690 for(int i=0;i<nbTS;i++)
692 MCAuto<MEDFileAnyTypeField1TS> f1ts(fs->getTimeStepAtPos(i));
693 std::vector<MEDCoupling::TypeOfField> tof(f1ts->getTypesOfFieldAvailable());
694 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=tof.begin();it!=tof.end();it++)
695 if(std::find(ret.begin(),ret.end(),*it)==ret.end())
698 // sort ret to put before ON_NODES then ON_CELLS then the remaining.
699 std::vector<MEDCoupling::TypeOfField> ret2;
700 if(std::find(ret.begin(),ret.end(),ON_NODES)!=ret.end())
701 ret2.push_back(ON_NODES);
702 if(std::find(ret.begin(),ret.end(),ON_CELLS)!=ret.end())
703 ret2.push_back(ON_CELLS);
704 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=ret.begin();it!=ret.end();it++)
705 if(*it!=ON_NODES && *it!=ON_CELLS)
710 std::vector<std::string> MEDCoupling::GetAllFieldNames(const std::string& fileName)
712 std::vector<std::string> ret;
713 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
714 med_int nbFields=MEDnField(fid);
715 med_field_type typcha;
716 for(int i=0;i<nbFields;i++)
718 med_int ncomp(MEDfieldnComponent(fid,i+1));
719 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
720 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
721 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
722 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
723 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
726 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
727 ret.push_back(std::string(nomcha));
732 std::vector<std::string> MEDCoupling::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
734 std::vector<std::string> ret;
735 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
736 med_int nbFields=MEDnField(fid);
738 med_field_type typcha;
739 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
740 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
742 for(int i=0;i<nbFields;i++)
744 med_int ncomp(MEDfieldnComponent(fid,i+1));
745 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
746 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
747 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
750 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
751 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
752 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
754 if(curMeshName==meshName)
755 ret.push_back(curFieldName);
762 std::vector<std::string> MEDCoupling::GetFieldNamesOnMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName)
764 MEDCoupling::CheckFileForRead(fileName);
768 return GetCellFieldNamesOnMesh(fileName,meshName);
770 return GetNodeFieldNamesOnMesh(fileName,meshName);
772 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
776 std::vector<std::string> MEDCoupling::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
778 std::vector<std::string> ret;
779 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
780 med_int nbFields=MEDnField(fid);
782 med_field_type typcha;
783 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
784 med_int numdt=0,numo=0;
786 char pflname[MED_NAME_SIZE+1]="";
787 char locname[MED_NAME_SIZE+1]="";
788 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
789 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
790 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
794 for(int i=0;i<nbFields;i++)
796 med_int ncomp(MEDfieldnComponent(fid,i+1));
797 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
798 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
799 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
800 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
801 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
802 med_int profilesize,nbi;
803 if(curMeshName==meshName)
806 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
810 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
811 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
812 pflname,&profilesize,locname,&nbi));
816 ret.push_back(curFieldName);
825 std::vector<std::string> MEDCoupling::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
827 std::vector<std::string> ret;
828 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
829 med_int nbFields=MEDnField(fid);
830 char pflname[MED_NAME_SIZE+1]="";
831 char locname[MED_NAME_SIZE+1]="";
833 med_field_type typcha;
834 med_int numdt=0,numo=0;
836 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
837 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
838 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
841 for(int i=0;i<nbFields;i++)
843 med_int ncomp(MEDfieldnComponent(fid,i+1));
844 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
845 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
847 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
848 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
849 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
852 med_int profilesize,nbi;
853 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
854 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
855 pflname,&profilesize,locname,&nbi));
856 if(curMeshName==meshName && nbOfVal>0)
858 ret.push_back(curFieldName);
865 std::vector< std::pair< std::pair<int,int>, double> > MEDCoupling::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
867 std::vector< std::pair< std::pair<int,int>, double > > ret;
868 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
869 med_int nbFields=MEDnField(fid);
871 med_field_type typcha;
872 med_int numdt=0,numo=0;
874 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
875 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
876 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
879 std::ostringstream oss; oss << "GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
880 for(int i=0;i<nbFields;i++)
882 med_int ncomp(MEDfieldnComponent(fid,i+1));
883 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
884 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
886 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
887 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
888 if(curFieldName==fieldName)
890 for(int k=0;k<nbPdt;k++)
892 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
893 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
899 oss << "\"" << curFieldName << "\"";
900 if(i!=nbFields-1) oss << ", ";
904 throw INTERP_KERNEL::Exception(oss.str().c_str());
907 double MEDCoupling::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
909 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
910 med_int nbFields=MEDnField(fid);
912 med_field_type typcha;
913 med_int numdt=0,numo=0;
916 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
917 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
918 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
922 double ret=std::numeric_limits<double>::max();
923 for(int i=0;i<nbFields && !found;i++)
925 med_int ncomp(MEDfieldnComponent(fid,i+1));
926 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
927 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
929 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt));
930 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
931 if(curFieldName==fieldName)
934 for(int k=0;k<nbPdt;k++)
936 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
937 if(numdt==iteration && numo==order)
945 if(!found || !found2)
947 std::ostringstream oss;
948 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
949 throw INTERP_KERNEL::Exception(oss.str().c_str());
954 std::vector< std::pair<int,int> > MEDCoupling::GetFieldIterations(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
956 MEDCoupling::CheckFileForRead(fileName);
960 return GetCellFieldIterations(fileName,meshName,fieldName);
962 return GetNodeFieldIterations(fileName,meshName,fieldName);
964 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
968 std::vector< std::pair<int,int> > MEDCoupling::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
970 std::string meshNameCpp(meshName);
971 std::vector< std::pair<int,int> > ret;
972 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
973 med_int nbFields=MEDnField(fid);
975 med_field_type typcha;
976 med_int numdt=0,numo=0;
978 char pflname[MED_NAME_SIZE+1]="";
979 char locname[MED_NAME_SIZE+1]="";
980 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
981 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
982 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
985 std::ostringstream oss; oss << "GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
986 std::set<std::string> s2;
987 for(int i=0;i<nbFields;i++)
989 med_int ncomp(MEDfieldnComponent(fid,i+1));
990 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
991 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
993 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
994 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
995 if(curFieldName==fieldName)
998 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
1000 for(int k=0;k<nbPdt;k++)
1002 med_int profilesize,nbi;
1003 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
1004 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
1005 pflname,&profilesize,locname,&nbi));
1006 std::string maa_ass_cpp(maa_ass);
1009 if(meshNameCpp==maa_ass_cpp)
1012 ret.push_back(std::make_pair(numdt,numo));
1015 s2.insert(maa_ass_cpp);
1022 oss << "\"" << curFieldName << "\"";
1023 if(i!=nbFields-1) oss << ", ";
1030 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1031 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1034 throw INTERP_KERNEL::Exception(oss.str().c_str());
1039 std::vector< std::pair<int,int> > MEDCoupling::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
1041 std::string meshNameCpp(meshName);
1042 std::vector< std::pair<int,int> > ret;
1043 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
1044 med_int nbFields=MEDnField(fid);
1046 med_field_type typcha;
1047 med_int numdt=0,numo=0;
1049 char pflname[MED_NAME_SIZE+1]="";
1050 char locname[MED_NAME_SIZE+1]="";
1051 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1052 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
1053 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1056 std::ostringstream oss; oss << "GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
1057 std::set<std::string> s2;
1058 for(int i=0;i<nbFields;i++)
1060 med_int ncomp(MEDfieldnComponent(fid,i+1));
1061 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
1062 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1064 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
1065 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1066 if(curFieldName==fieldName)
1068 for(int k=0;k<nbPdt;k++)
1070 med_int profilesize,nbi;
1071 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
1072 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1073 pflname,&profilesize,locname,&nbi));
1074 std::string maa_ass_cpp(maa_ass);
1077 if(meshNameCpp==maa_ass_cpp)
1078 { ret.push_back(std::make_pair(numdt,numo)); }
1080 s2.insert(maa_ass_cpp);
1086 oss << "\"" << curFieldName << "\"";
1087 if(i!=nbFields-1) oss << ", ";
1094 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1095 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1098 throw INTERP_KERNEL::Exception(oss.str().c_str());
1103 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1105 MEDCoupling::CheckFileForRead(fileName);
1106 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1107 MEDFileMesh *mmPtr(mm);
1108 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1110 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1111 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1114 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1115 return const_cast<MEDCouplingCMesh *>(ret);
1117 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1120 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1121 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1123 std::ostringstream oss; oss << "ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1124 throw INTERP_KERNEL::Exception(oss.str().c_str());
1127 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1129 MEDCoupling::CheckFileForRead(fileName);
1130 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1131 MEDFileMesh *mmPtr(mm);
1132 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1134 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1135 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1138 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1139 return const_cast<MEDCouplingCMesh *>(ret);
1141 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1144 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1145 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1147 std::ostringstream oss; oss << "ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1148 throw INTERP_KERNEL::Exception(oss.str().c_str());
1151 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1153 MEDCoupling::CheckFileForRead(fileName);
1154 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1155 MEDFileMesh *mmPtr(mm);
1156 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1159 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1160 throw INTERP_KERNEL::Exception(oss.str().c_str());
1162 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1165 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1167 MEDCoupling::CheckFileForRead(fileName);
1168 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1169 MEDFileMesh *mmPtr(mm);
1170 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1173 std::ostringstream oss; oss << "ReadUMeshFromFile : 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->getMeshAtLevel(meshDimRelToMax,true);
1179 int MEDCoupling::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1181 MEDCoupling::CheckFileForRead(fileName);
1182 std::vector<int> poss;
1183 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1186 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1188 MEDCoupling::CheckFileForRead(fileName);
1189 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1190 MEDFileMesh *mmPtr(mm);
1191 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1194 std::ostringstream oss; oss << "ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1195 throw INTERP_KERNEL::Exception(oss.str().c_str());
1197 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1200 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1202 MEDCoupling::CheckFileForRead(fileName);
1203 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1204 MEDFileMesh *mmPtr(mm);
1205 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1208 std::ostringstream oss; oss << "ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1209 throw INTERP_KERNEL::Exception(oss.str().c_str());
1211 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1214 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName)
1216 std::vector<std::string> fieldNames(GetAllFieldNames(fileName));
1217 std::size_t sz(fieldNames.size());
1220 std::ostringstream oss;
1221 oss << "The file \"" << fileName << "\" contains no field !";
1222 throw INTERP_KERNEL::Exception(oss.str());
1226 std::ostringstream oss;
1227 oss << "In file \"" << fileName << "\" there are more than one field !" << std::endl;
1228 oss << "You are invited to use ReadField(fileName, fieldName) instead to avoid misleading concerning field you want to read !" << std::endl;
1229 oss << "For information, fields available are :" << std::endl;
1230 for(std::vector<std::string>::const_iterator it=fieldNames.begin();it!=fieldNames.end();it++)
1231 oss << " - \"" << *it << "\"" << std::endl;
1232 throw INTERP_KERNEL::Exception(oss.str());
1234 return ReadField(fileName,fieldNames[0]);
1237 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName)
1239 std::vector< std::pair< std::pair<int,int>, double> > iterations(GetAllFieldIterations(fileName,fieldName));
1240 std::size_t sz(iterations.size());
1243 std::ostringstream oss;
1244 oss << "In file \"" << fileName << "\" field \"" << fieldName << "\" exists but with no time steps !";
1245 throw INTERP_KERNEL::Exception(oss.str());
1249 std::ostringstream oss;
1250 oss << "In file \"" << fileName << "\" field \"" << fieldName << "\" exists but with more than one time steps !" << std::endl;
1251 oss << "You are invited to use ReadField(fileName, fieldName, iteration, order) instead to avoid misleading concerning time steps." << std::endl;
1252 oss << "For information, time steps available for field \"" << fieldName << "\" are :" << std::endl;
1253 for(std::vector< std::pair< std::pair<int,int>, double> >::const_iterator it=iterations.begin();it!=iterations.end();it++)
1254 oss << " - " << (*it).first.first << ", " << (*it).first.second << " (" << (*it).second << ")" << std::endl;
1255 throw INTERP_KERNEL::Exception(oss.str());
1257 return ReadField(fileName,fieldName,iterations[0].first.first,iterations[0].first.second);
1260 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order)
1262 MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
1263 MCAuto<MEDFileMesh> mesh(MEDFileMesh::New(fileName,f->getMeshName()));
1265 MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
1268 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(f1->field(mesh));
1269 return MEDCoupling::DynamicCast<MEDCouplingFieldDouble,MEDCouplingField>(ret);
1273 MCAuto<MEDFileInt32Field1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileInt32Field1TS>(f));
1276 MCAuto<MEDCoupling::MEDCouplingFieldInt32> ret(f1->field(mesh));
1277 return MEDCoupling::DynamicCast<MEDCouplingFieldInt32,MEDCouplingField>(ret);
1281 MCAuto<MEDFileInt64Field1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileInt64Field1TS>(f));
1284 MCAuto<MEDCoupling::MEDCouplingFieldInt64> ret(f1->field(mesh));
1285 return MEDCoupling::DynamicCast<MEDCouplingFieldInt64,MEDCouplingField>(ret);
1289 MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
1292 MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(f1->field(mesh));
1293 return MEDCoupling::DynamicCast<MEDCouplingFieldFloat,MEDCouplingField>(ret);
1297 throw INTERP_KERNEL::Exception("MEDCoupling::ReadField : only FLOAT32, FLOAT64, INT32 and INT64 supported for the moment !");
1300 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)
1302 MEDCoupling::CheckFileForRead(fileName);
1306 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1308 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1310 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1312 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1314 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1318 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsOnSameMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1319 const std::vector<std::pair<int,int> >& its)
1322 return std::vector<MEDCoupling::MEDCouplingFieldDouble *>();
1323 MEDCoupling::CheckFileForRead(fileName);
1324 std::vector<MEDCoupling::MEDCouplingFieldDouble *> ret(its.size());
1325 std::vector< MCAuto<MEDCouplingFieldDouble> > retSafe(its.size());
1328 //Retrieving mesh of rank 0 and field on rank 0 too.
1329 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1330 MEDFileMesh *mmPtr(mm);
1331 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1333 throw INTERP_KERNEL::Exception("ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1334 MCAuto<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1335 const DataArrayIdType *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1336 MCAuto<MEDCouplingUMesh> m2(m->clone(true));
1338 m2->renumberCells(o2n->begin(),true);
1340 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1342 MCAuto<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1343 MCAuto<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1345 retElt->renumberCells(o2n->begin(),true);
1346 retElt->setMesh(m2);
1350 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1351 ret[i]=retSafe[i].retn();
1355 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1356 const std::vector<std::pair<int,int> >& its)
1358 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1361 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1362 const std::vector<std::pair<int,int> >& its)
1364 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1367 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1368 const std::vector<std::pair<int,int> >& its)
1370 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1373 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1374 const std::vector<std::pair<int,int> >& its)
1376 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1379 namespace MEDCoupling
1382 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)
1384 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1385 MCAuto<MEDFileUMesh> muPtr(MEDCoupling::DynamicCast<MEDFileMesh,MEDFileUMesh>(mm));
1386 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1387 MCAuto<typename Traits<T>::FieldType> ret(ff->getFieldOnMeshAtLevel(type,m));
1388 if(muPtr.isNotNull())
1390 const DataArrayIdType *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1392 ret->renumberCells(num->begin());
1397 MEDCoupling::MEDCouplingField *ReadFieldCellLike(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1399 MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
1401 MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
1404 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(ReadFieldCellLikeT<double>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1409 MCAuto<MEDFileInt32Field1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileInt32Field1TS>(f));
1412 MCAuto<MEDCoupling::MEDCouplingFieldInt32> ret(ReadFieldCellLikeT<int>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1417 MCAuto<MEDFileInt64Field1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileInt64Field1TS>(f));
1420 MCAuto<MEDCoupling::MEDCouplingFieldInt64> ret(ReadFieldCellLikeT<Int64>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1425 MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
1428 MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(ReadFieldCellLikeT<float>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1432 throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldCell : only FLOAT32, FLOAT64, INT32 and INT64 supported for the moment !");
1436 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)
1438 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1439 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1440 MCAuto<typename Traits<T>::FieldType> ret(ff->getFieldOnMeshAtLevel(ON_NODES,m));
1441 MCAuto<MEDFileUMesh> muPtr(MEDCoupling::DynamicCast<MEDFileMesh,MEDFileUMesh>(mm));
1442 if(ff->getPflsReallyUsed().empty())
1444 if(muPtr.isNotNull())
1446 const DataArrayIdType *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1448 ret->renumberCells(num->begin());
1453 DataArrayIdType *pfl(nullptr),*arr2(nullptr);
1454 MCAuto<typename Traits<T>::ArrayType> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl));
1455 MCAuto<DataArrayIdType> pflSafe(pfl);
1456 MCAuto<DataArrayIdType> mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end()));
1457 MCAuto<MEDCouplingUMesh> mzip(static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2)));
1458 MCAuto<DataArrayIdType> arr2Safe(arr2);
1459 MCAuto<DataArrayIdType> arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes()));
1460 MCAuto<DataArrayIdType> pflSorted(pflSafe->deepCopy()); pflSorted->sort(true);
1461 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1462 throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !");
1463 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1465 MCAuto<DataArrayIdType> o2n2(pflSafe->checkAndPreparePermutation());
1466 MCAuto<DataArrayIdType> n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples()));
1467 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1477 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1479 return ReadFieldCellLike(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1482 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1484 MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
1486 MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
1489 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(ReadFieldNodeT<double>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1494 MCAuto<MEDFileInt32Field1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileInt32Field1TS>(f));
1497 MCAuto<MEDCoupling::MEDCouplingFieldInt32> ret(ReadFieldNodeT<int>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1502 MCAuto<MEDFileInt64Field1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileInt64Field1TS>(f));
1505 MCAuto<MEDCoupling::MEDCouplingFieldInt64> ret(ReadFieldNodeT<Int64>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1510 MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
1513 MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(ReadFieldNodeT<float>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1517 throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldNode : only FLOAT32, FLOAT64, INT32 and INT64 supported for the moment !");
1520 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1522 return ReadFieldCellLike(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1525 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1527 return ReadFieldCellLike(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1530 void MEDCoupling::WriteMesh(const std::string& fileName, const MEDCoupling::MEDCouplingMesh *mesh, bool writeFromScratch)
1533 throw INTERP_KERNEL::Exception("WriteMesh : input mesh is null !");
1534 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1537 WriteUMesh(fileName,um,writeFromScratch);
1540 int mod=writeFromScratch?2:0;
1541 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1544 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1545 AssignStaticWritePropertiesTo(*mmu);
1546 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1547 mmu->write(fileName,mod);
1550 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1553 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1554 AssignStaticWritePropertiesTo(*mmc);
1555 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1556 mmc->write(fileName,mod);
1559 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1562 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1563 AssignStaticWritePropertiesTo(*mmc);
1564 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1565 mmc->write(fileName,mod);
1568 throw INTERP_KERNEL::Exception("WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1571 void MEDCoupling::WriteUMesh(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1574 throw INTERP_KERNEL::Exception("WriteUMesh : input mesh is null !");
1575 int mod=writeFromScratch?2:0;
1576 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1577 AssignStaticWritePropertiesTo(*m);
1578 MCAuto<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCopy()));
1579 m->setMeshAtLevel(0,mcpy,true);
1580 m->write(fileName,mod);
1583 void MEDCoupling::WriteUMeshDep(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1585 WriteUMesh(fileName,mesh,writeFromScratch);
1588 void MEDCoupling::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1590 std::string meshName(meshNameC);
1591 if(meshName.empty())
1592 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 !");
1593 int status=MEDLoaderBase::getStatusOfFile(fileName);
1594 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1596 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1597 throw INTERP_KERNEL::Exception(oss.str().c_str());
1599 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1600 AssignStaticWritePropertiesTo(*m);
1601 m->setGroupsFromScratch(0,meshes,true);
1602 m->setName(meshNameC);
1603 int mod=writeFromScratch?2:0;
1604 m->write(fileName,mod);
1607 void MEDCoupling::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1609 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1612 void MEDCoupling::WriteUMeshes(const std::string& fileName, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1614 int mod(writeFromScratch?2:0);
1615 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1616 AssignStaticWritePropertiesTo(*m);
1617 m->setMeshes(meshes,true);
1618 m->write(fileName,mod);
1622 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f, bool writeFromScratch)
1624 MCAuto< typename MLFieldTraits<T>::F1TSType > ff(MLFieldTraits<T>::F1TSType::New());
1625 AssignStaticWritePropertiesTo(*ff);
1626 MCAuto<typename MEDCoupling::Traits<T>::FieldType> f2(f->deepCopy());
1627 const MEDCouplingMesh *m(f2->getMesh());
1628 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1629 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1630 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1631 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1632 MCAuto<MEDFileMesh> mm;
1633 int mod(writeFromScratch?2:0);
1636 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1637 AssignStaticWritePropertiesTo(*mmu);
1638 MCAuto<DataArrayIdType> o2n(um->getRenumArrForMEDFileFrmt());
1639 MCAuto<DataArrayIdType> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1640 f2->renumberCells(o2n->begin(),false);
1641 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1642 mmu->setRenumFieldArr(0,n2o);
1643 ff->setFieldNoProfileSBT(f2);
1644 mmu->write(fileName,mod);
1648 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1649 AssignStaticWritePropertiesTo(*mmu);
1650 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1651 ff->setFieldNoProfileSBT(f2);
1652 mmu->write(fileName,mod);
1656 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1657 AssignStaticWritePropertiesTo(*mmc);
1658 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1659 ff->setFieldNoProfileSBT(f2);
1660 mmc->write(fileName,mod);
1664 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1665 AssignStaticWritePropertiesTo(*mmc);
1666 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1667 ff->setFieldNoProfileSBT(f2);
1668 mmc->write(fileName,mod);
1671 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1672 ff->write(fileName,0);
1676 void WriteFieldT(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f, bool writeFromScratch)
1679 throw INTERP_KERNEL::Exception("WriteField : input field is NULL !");
1680 f->checkConsistencyLight();
1681 int status(MEDLoaderBase::getStatusOfFile(fileName));
1682 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1684 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1685 throw INTERP_KERNEL::Exception(oss.str().c_str());
1687 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1689 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile<T>(fileName,f,true);
1693 std::vector<std::string> meshNames(GetMeshNames(fileName));
1695 throw INTERP_KERNEL::Exception("WriteField : trying to write a field with no mesh !");
1696 std::string fileNameCpp(f->getMesh()->getName());
1697 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1698 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile<T>(fileName,f,false);
1701 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1702 AssignStaticWritePropertiesTo(*mm);
1703 const MEDFileMesh *mmPtr(mm);
1704 const MEDFileUMesh *mmuPtr(dynamic_cast<const MEDFileUMesh *>(mmPtr));
1706 throw INTERP_KERNEL::Exception("WriteField : only umeshes are supported now !");
1707 MCAuto< typename MEDCoupling::Traits<T>::FieldType > f2(f->deepCopy());
1708 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh())));
1710 throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !");
1711 MCAuto<DataArrayIdType> o2n(m->getRenumArrForMEDFileFrmt());
1712 f2->renumberCells(o2n->begin(),false);
1713 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1714 MCAuto<MEDCouplingUMesh> mread(mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension()));
1715 if(f2->getTypeOfField()!=ON_NODES)
1717 if(!m->getCoords()->isEqualWithoutConsideringStr(*mread->getCoords(),_EPS_FOR_NODE_COMP))
1718 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1720 mread->setCoords(m->getCoords());
1721 DataArrayIdType *part(NULL);
1722 bool b(mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part));
1723 MCAuto<DataArrayIdType> partSafe(part);
1726 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 !";
1727 throw INTERP_KERNEL::Exception(oss.str().c_str());
1729 MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
1730 AssignStaticWritePropertiesTo(*f1ts);
1731 if(part->isIota(mread->getNumberOfCells()))
1732 f1ts->setFieldNoProfileSBT(f2);
1735 part->setName(f1ts->createNewNameOfPfl().c_str());
1736 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1738 f1ts->write(fileName,0);
1743 DataArrayIdType *part(NULL);
1744 bool b(mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part));
1745 MCAuto<DataArrayIdType> partSafe(part);
1748 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 !";
1749 throw INTERP_KERNEL::Exception(oss.str().c_str());
1751 MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
1752 AssignStaticWritePropertiesTo(*f1ts);
1753 if(part->isIota(mread->getNumberOfNodes()))
1754 f1ts->setFieldNoProfileSBT(f2);
1757 part->setName(f1ts->createNewNameOfPfl().c_str());
1758 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1760 f1ts->write(fileName,0);
1766 void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch)
1769 throw INTERP_KERNEL::Exception("WriteField : input field is null !");
1771 const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldDouble *>(f));
1774 WriteFieldT<double>(fileName,f1,writeFromScratch);
1779 const MEDCoupling::MEDCouplingFieldInt32 *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt32 *>(f));
1782 WriteFieldT<int>(fileName,f1,writeFromScratch);
1787 const MEDCoupling::MEDCouplingFieldInt64 *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt64 *>(f));
1790 WriteFieldT<Int64>(fileName,f1,writeFromScratch);
1796 const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldFloat *>(f));
1799 WriteFieldT<float>(fileName,f1,writeFromScratch);
1803 throw INTERP_KERNEL::Exception("WriteField : input field is not in FLOAT32, FLOAT64, INT32 and INT64!");
1806 void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch)
1808 WriteField(fileName,f,writeFromScratch);
1812 void WriteFieldUsingAlreadyWrittenMeshT(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f)
1815 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMeshT : input field is null !");
1816 f->checkConsistencyLight();
1817 int status(MEDLoaderBase::getStatusOfFile(fileName));
1818 if(status!=MEDLoaderBase::EXIST_RW)
1820 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1821 throw INTERP_KERNEL::Exception(oss.str().c_str());
1823 MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
1824 AssignStaticWritePropertiesTo(*f1ts);
1825 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1828 MCAuto<DataArrayIdType> o2n(m->getRenumArrForMEDFileFrmt());
1829 MCAuto< typename MEDCoupling::Traits<T>::FieldType > f2(f->deepCopy());
1830 f2->renumberCells(o2n->begin(),false);
1831 f1ts->setFieldNoProfileSBT(f2);
1834 f1ts->setFieldNoProfileSBT(f);
1835 f1ts->write(fileName,0);
1838 void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingField *f)
1841 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1843 const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldDouble *>(f));
1846 WriteFieldUsingAlreadyWrittenMeshT<double>(fileName,f1);
1851 const MEDCoupling::MEDCouplingFieldInt32 *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt32 *>(f));
1854 WriteFieldUsingAlreadyWrittenMeshT<int>(fileName,f1);
1859 const MEDCoupling::MEDCouplingFieldInt64 *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt64 *>(f));
1862 WriteFieldUsingAlreadyWrittenMeshT<Int64>(fileName,f1);
1867 const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldFloat *>(f));
1870 WriteFieldUsingAlreadyWrittenMeshT<float>(fileName,f1);
1874 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is not in FLOAT32, FLOAT64, INT32 and INT64 !");