1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDLoader.hxx"
22 #include "MEDLoaderBase.hxx"
23 #include "MEDFileUtilities.hxx"
24 #include "MEDLoaderNS.hxx"
25 #include "MEDFileSafeCaller.txx"
26 #include "MEDFileMesh.hxx"
27 #include "MEDFileField.hxx"
28 #include "CellModel.hxx"
29 #include "MEDCouplingUMesh.hxx"
30 #include "MEDCouplingMemArray.hxx"
31 #include "MEDCouplingFieldDouble.hxx"
32 #include "MEDCouplingFieldFloat.hxx"
33 #include "MEDCouplingFieldInt.hxx"
34 #include "MEDCouplingGaussLocalization.hxx"
35 #include "MEDCouplingTraits.hxx"
38 #include "InterpKernelAutoPtr.hxx"
52 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
77 med_geometry_type typmainoeud[1] = { MED_NONE };
79 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
80 INTERP_KERNEL::NORM_SEG2,
81 INTERP_KERNEL::NORM_SEG3,
82 INTERP_KERNEL::NORM_SEG4,
83 INTERP_KERNEL::NORM_TRI3,
84 INTERP_KERNEL::NORM_QUAD4,
85 INTERP_KERNEL::NORM_TRI6,
86 INTERP_KERNEL::NORM_TRI7,
87 INTERP_KERNEL::NORM_QUAD8,
88 INTERP_KERNEL::NORM_QUAD9,
89 INTERP_KERNEL::NORM_TETRA4,
90 INTERP_KERNEL::NORM_PYRA5,
91 INTERP_KERNEL::NORM_PENTA6,
92 INTERP_KERNEL::NORM_HEXA8,
93 INTERP_KERNEL::NORM_HEXGP12,
94 INTERP_KERNEL::NORM_TETRA10,
95 INTERP_KERNEL::NORM_PYRA13,
96 INTERP_KERNEL::NORM_PENTA15,
97 INTERP_KERNEL::NORM_PENTA18,
98 INTERP_KERNEL::NORM_HEXA20,
99 INTERP_KERNEL::NORM_HEXA27,
100 INTERP_KERNEL::NORM_POLYGON,
101 INTERP_KERNEL::NORM_QPOLYG,
102 INTERP_KERNEL::NORM_POLYHED };
104 med_geometry_type typmai3[34] = { MED_POINT1,//0
140 double _EPS_FOR_NODE_COMP=1.e-12;
142 int _COMP_FOR_CELL=0;
146 using namespace MEDCoupling;
151 * This method returns a first quick overview of mesh with name \a meshName into the file \a fileName.
152 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
153 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
155 int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities)
157 possibilities.clear();
158 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
161 char nommaa[MED_NAME_SIZE+1];
162 char maillage_description[MED_COMMENT_SIZE+1];
163 med_mesh_type type_maillage;
165 std::string trueMeshName;
166 med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
167 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
168 med_sorting_type sortingType;
170 med_axis_type axisType;
171 int naxis(MEDmeshnAxis(fid,meshId));
172 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
173 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
174 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
178 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
182 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
184 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
186 med_geometry_type curMedType=typmai[i];
187 med_bool changement,transformation;
188 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
189 int curNbOfElemF(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));//limitation
191 med_entity_type whichEntity;
192 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
195 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
196 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
203 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
204 possibilities.push_back(*it-ret);
211 med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName)
215 std::vector<std::string> meshes=getMeshNamesFid(fid);
217 throw INTERP_KERNEL::Exception("No mesh in file");
218 trueMeshName=meshes[0];
221 std::string meshNameStr(meshName);
222 std::vector<std::string> meshes=getMeshNamesFid(fid);
224 throw INTERP_KERNEL::Exception("No mesh in file");
225 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
226 if(iter==meshes.end())
228 std::ostringstream os2;
229 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
230 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
231 throw INTERP_KERNEL::Exception(os2.str().c_str());
233 trueMeshName=meshName;
234 return iter-meshes.begin()+1;
237 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
239 med_mesh_type type_maillage;
240 char maillage_description[MED_COMMENT_SIZE+1];
241 char dtunit[MED_COMMENT_SIZE+1];
244 char nommaa[MED_NAME_SIZE+1];
245 med_axis_type axistype;
246 med_sorting_type stype;
247 med_int n=MEDnMesh(fid);
248 std::vector<std::string> ret(n);
251 int naxis(MEDmeshnAxis(fid,i+1));
252 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
253 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
255 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
256 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
263 * This methods allows to merger all entities and to considerate only cell types.
265 void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
267 if(nbOfElemCell>=nbOfElemFace)
269 whichEntity=MED_CELL;
270 nbOfElem=nbOfElemCell;
274 whichEntity=MED_CELL;
275 nbOfElem=nbOfElemFace;
281 void MEDCoupling::AssignStaticWritePropertiesTo(MEDCoupling::MEDFileWritable& obj)
283 obj.setTooLongStrPolicy(_TOO_LONG_STR);
286 bool MEDCoupling::HasXDR()
295 std::string MEDCoupling::MEDFileVersionStr()
299 std::fill(buf,buf+SZ,'\0');
300 const char START_EXPECTED[]="MED-";
301 med_err ret(MEDlibraryStrVersion(buf));
303 throw INTERP_KERNEL::Exception("MEDFileVersionStr : fail to find version of MED file ! It looks very bad !");
304 std::string zeRet(buf);
305 std::size_t pos(zeRet.find(START_EXPECTED,0));
308 std::ostringstream oss; oss << "MEDFileVersionStr : internal error ! The MEDFile returned version (\"" << zeRet << "\") has not the right pattern !";
309 throw INTERP_KERNEL::Exception(oss.str());
311 return zeRet.substr(sizeof(START_EXPECTED)-1,std::string::npos);
314 std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
316 #if MED_NUM_MAJEUR>3 || ( MED_NUM_MAJEUR==3 && ( (MED_NUM_MINEUR==2 && MED_NUM_RELEASE>=1) || MED_NUM_MINEUR>=3) )
317 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
319 const char START_EXPECTED[]="MED-";
321 std::fill(buf,buf+SZ,'\0');
322 MEDFILESAFECALLERRD0(MEDfileStrVersionRd,(fid,buf));
323 std::string ret(buf);
324 std::size_t pos(ret.find(START_EXPECTED,0));
327 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : internal error ! The MEDFile returned version (\"" << ret << "\") has not the right pattern !";
328 throw INTERP_KERNEL::Exception(oss.str());
330 return ret.substr(sizeof(START_EXPECTED)-1,std::string::npos);
332 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : is implemented with MEDFile " << MEDFileVersionStr() << " ! If you need this feature please use version >= 3.2.1.";
333 throw INTERP_KERNEL::Exception(oss.str());
337 void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
339 med_int majj,minn,rell;
340 med_err ret(MEDlibraryNumVersion(&majj,&minn,&rell));
342 throw INTERP_KERNEL::Exception("MEDFileVersion : fail to call MEDlibraryNumVersion ! It looks very bad !");
349 * 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.
351 void MEDCoupling::SetEpsilonForNodeComp(double val)
353 _EPS_FOR_NODE_COMP=val;
357 * 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.
359 void MEDCoupling::SetCompPolicyForCell(int val)
365 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
366 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
368 void MEDCoupling::SetTooLongStrPolicy(int val)
374 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
375 * It returns, in this order :
376 * - 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...
377 * - the mesh dimension
378 * - the space dimension
379 * - the number of nodes
381 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > MEDCoupling::GetUMeshGlobalInfo(const std::string& fileName, const std::string& meshName, int &meshDim, int& spaceDim, int& numberOfNodes)
383 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
385 char nommaa[MED_NAME_SIZE+1];
386 char maillage_description[MED_COMMENT_SIZE+1];
387 med_mesh_type type_maillage;
388 std::string trueMeshName;
389 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
390 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
391 med_sorting_type sortingType;
393 med_axis_type axisType;
394 int naxis(MEDmeshnAxis(fid,meshId));
395 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
396 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
397 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
398 if(type_maillage!=MED_UNSTRUCTURED_MESH)
400 std::ostringstream oss; oss << "GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
401 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
402 throw INTERP_KERNEL::Exception(oss.str().c_str());
406 throw INTERP_KERNEL::Exception("GetUMeshGlobalInfo : multisteps on mesh not managed !");
409 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
411 std::vector<int> dims;
412 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
413 med_bool changement,transformation;
414 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
416 med_geometry_type curMedType=typmai[i];
417 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
420 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
421 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
422 dims.push_back(mdimCell);
423 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
426 int maxLev=*std::max_element(dims.begin(),dims.end());
427 int lowLev=*std::min_element(dims.begin(),dims.end());
428 int nbOfLevels=maxLev-lowLev+1;
429 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
430 for(std::size_t i=0;i<dims.size();i++)
432 ret[maxLev-dims[i]].push_back(geoTypes[i]);
434 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
438 void MEDCoupling::CheckFileForRead(const std::string& fileName)
440 MEDFileUtilities::CheckFileForRead(fileName);
443 std::vector<std::string> MEDCoupling::GetMeshNames(const std::string& fileName)
445 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
446 return MEDLoaderNS::getMeshNamesFid(fid);
449 std::vector< std::pair<std::string,std::string> > MEDCoupling::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
451 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
452 med_int nbFields(MEDnField(fid));
453 std::vector<std::string> fields(nbFields);
454 med_field_type typcha;
455 for(int i=0;i<nbFields;i++)
457 med_int ncomp(MEDfieldnComponent(fid,i+1));
458 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
459 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
460 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
463 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
464 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
465 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
466 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
467 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
468 if(curFieldName==fieldName)
470 std::vector< std::pair<std::string,std::string> > ret(ncomp);
471 for(int j=0;j<ncomp;j++)
472 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
473 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
476 fields[i]=curFieldName;
478 std::ostringstream oss; oss << "GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
479 oss << "Possible field names are : " << std::endl;
480 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
481 throw INTERP_KERNEL::Exception(oss.str().c_str());
484 std::vector<std::string> MEDCoupling::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
486 std::vector<std::string> ret;
488 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
489 med_int nbFields=MEDnField(fid);
491 med_field_type typcha;
492 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
493 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
496 for(int i=0;i<nbFields;i++)
498 med_int ncomp(MEDfieldnComponent(fid,i+1));
499 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
500 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
502 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
503 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
504 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
505 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
506 if(curFieldName==fieldName)
507 ret.push_back(meshName);
512 std::vector<std::string> MEDCoupling::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
514 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
515 med_int nfam=MEDnFamily(fid,meshName.c_str());
516 std::vector<std::string> ret(nfam);
517 char nomfam[MED_NAME_SIZE+1];
519 for(int i=0;i<nfam;i++)
521 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
522 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
523 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
524 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
525 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
526 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
527 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
528 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
535 std::vector<std::string> MEDCoupling::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
537 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
538 med_int nfam=MEDnFamily(fid,meshName.c_str());
539 std::vector<std::string> ret;
540 char nomfam[MED_NAME_SIZE+1];
542 for(int i=0;i<nfam;i++)
544 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
545 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
546 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
547 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
548 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
549 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
550 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
551 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
552 for(int j=0;j<ngro;j++)
554 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
562 std::vector<std::string> MEDCoupling::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
564 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
565 med_int nfam(MEDnFamily(fid,meshName.c_str()));
566 std::vector<std::string> ret;
567 char nomfam[MED_NAME_SIZE+1];
570 for(int i=0;i<nfam && !found;i++)
572 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
573 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
574 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
575 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
576 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
577 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
578 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
579 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
580 found=(cur==famName);
582 for(int j=0;j<ngro;j++)
584 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
590 std::ostringstream oss;
591 oss << "GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
592 throw INTERP_KERNEL::Exception(oss.str().c_str());
598 std::vector<std::string> MEDCoupling::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
600 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
601 med_int nfam=MEDnFamily(fid,meshName.c_str());
602 std::vector<std::string> ret;
603 char nomfam[MED_NAME_SIZE+1];
605 for(int i=0;i<nfam;i++)
607 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
608 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
609 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
610 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
611 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
612 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
613 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
614 for(int j=0;j<ngro;j++)
616 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
617 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
624 std::vector<MEDCoupling::TypeOfField> MEDCoupling::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
626 std::vector<MEDCoupling::TypeOfField> ret;
627 MCAuto<MEDFileAnyTypeFieldMultiTS> fs(MEDFileAnyTypeFieldMultiTS::New(fileName,fieldName,false));
628 if(fs->getMeshName()!=meshName)
630 std::ostringstream oss; oss << "GetTypesOfField : The field \"" << fieldName << "\" in file \"" << fileName << "\" is not lying on mesh \"" << meshName << "\"";
631 oss << " The name of the mesh in file is \"" << fs->getMeshName() << "\"!";
632 throw INTERP_KERNEL::Exception(oss.str().c_str());
634 int nbTS(fs->getNumberOfTS());
637 for(int i=0;i<nbTS;i++)
639 MCAuto<MEDFileAnyTypeField1TS> f1ts(fs->getTimeStepAtPos(i));
640 std::vector<MEDCoupling::TypeOfField> tof(f1ts->getTypesOfFieldAvailable());
641 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=tof.begin();it!=tof.end();it++)
642 if(std::find(ret.begin(),ret.end(),*it)==ret.end())
645 // sort ret to put before ON_NODES then ON_CELLS then the remaining.
646 std::vector<MEDCoupling::TypeOfField> ret2;
647 if(std::find(ret.begin(),ret.end(),ON_NODES)!=ret.end())
648 ret2.push_back(ON_NODES);
649 if(std::find(ret.begin(),ret.end(),ON_CELLS)!=ret.end())
650 ret2.push_back(ON_CELLS);
651 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=ret.begin();it!=ret.end();it++)
652 if(*it!=ON_NODES && *it!=ON_CELLS)
657 std::vector<std::string> MEDCoupling::GetAllFieldNames(const std::string& fileName)
659 std::vector<std::string> ret;
660 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
661 med_int nbFields=MEDnField(fid);
662 med_field_type typcha;
663 for(int i=0;i<nbFields;i++)
665 med_int ncomp(MEDfieldnComponent(fid,i+1));
666 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
667 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
668 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
669 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
670 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
673 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
674 ret.push_back(std::string(nomcha));
679 std::vector<std::string> MEDCoupling::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
681 std::vector<std::string> ret;
682 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
683 med_int nbFields=MEDnField(fid);
685 med_field_type typcha;
686 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
687 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
689 for(int i=0;i<nbFields;i++)
691 med_int ncomp(MEDfieldnComponent(fid,i+1));
692 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
693 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
694 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
697 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
698 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
699 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
701 if(curMeshName==meshName)
702 ret.push_back(curFieldName);
709 std::vector<std::string> MEDCoupling::GetFieldNamesOnMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName)
711 MEDCoupling::CheckFileForRead(fileName);
715 return GetCellFieldNamesOnMesh(fileName,meshName);
717 return GetNodeFieldNamesOnMesh(fileName,meshName);
719 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
723 std::vector<std::string> MEDCoupling::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
725 std::vector<std::string> ret;
726 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
727 med_int nbFields=MEDnField(fid);
729 med_field_type typcha;
730 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
731 med_int numdt=0,numo=0;
733 char pflname[MED_NAME_SIZE+1]="";
734 char locname[MED_NAME_SIZE+1]="";
735 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
736 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
737 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
741 for(int i=0;i<nbFields;i++)
743 med_int ncomp(MEDfieldnComponent(fid,i+1));
744 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
745 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
746 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
747 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
748 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
750 if(curMeshName==meshName)
753 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
757 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
758 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
759 pflname,&profilesize,locname,&nbi));
763 ret.push_back(curFieldName);
772 std::vector<std::string> MEDCoupling::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
774 std::vector<std::string> ret;
775 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
776 med_int nbFields=MEDnField(fid);
777 char pflname[MED_NAME_SIZE+1]="";
778 char locname[MED_NAME_SIZE+1]="";
780 med_field_type typcha;
781 med_int numdt=0,numo=0;
783 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
784 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
785 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
788 for(int i=0;i<nbFields;i++)
790 med_int ncomp(MEDfieldnComponent(fid,i+1));
791 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
792 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
794 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
795 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
796 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
800 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
801 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
802 pflname,&profilesize,locname,&nbi));
803 if(curMeshName==meshName && nbOfVal>0)
805 ret.push_back(curFieldName);
812 std::vector< std::pair< std::pair<int,int>, double> > MEDCoupling::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
814 std::vector< std::pair< std::pair<int,int>, double > > ret;
815 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
816 med_int nbFields=MEDnField(fid);
818 med_field_type typcha;
819 med_int numdt=0,numo=0;
821 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
822 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
823 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
826 std::ostringstream oss; oss << "GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
827 for(int i=0;i<nbFields;i++)
829 med_int ncomp(MEDfieldnComponent(fid,i+1));
830 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
831 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
833 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
834 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
835 if(curFieldName==fieldName)
837 for(int k=0;k<nbPdt;k++)
839 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
840 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
846 oss << "\"" << curFieldName << "\"";
847 if(i!=nbFields-1) oss << ", ";
851 throw INTERP_KERNEL::Exception(oss.str().c_str());
854 double MEDCoupling::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
856 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
857 med_int nbFields=MEDnField(fid);
859 med_field_type typcha;
860 med_int numdt=0,numo=0;
863 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
864 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
865 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
869 double ret=std::numeric_limits<double>::max();
870 for(int i=0;i<nbFields && !found;i++)
872 med_int ncomp(MEDfieldnComponent(fid,i+1));
873 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
874 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
876 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt));
877 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
878 if(curFieldName==fieldName)
881 for(int k=0;k<nbPdt;k++)
883 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
884 if(numdt==iteration && numo==order)
892 if(!found || !found2)
894 std::ostringstream oss;
895 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
896 throw INTERP_KERNEL::Exception(oss.str().c_str());
901 std::vector< std::pair<int,int> > MEDCoupling::GetFieldIterations(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
903 MEDCoupling::CheckFileForRead(fileName);
907 return GetCellFieldIterations(fileName,meshName,fieldName);
909 return GetNodeFieldIterations(fileName,meshName,fieldName);
911 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
915 std::vector< std::pair<int,int> > MEDCoupling::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
917 std::string meshNameCpp(meshName);
918 std::vector< std::pair<int,int> > ret;
919 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
920 med_int nbFields=MEDnField(fid);
922 med_field_type typcha;
923 med_int numdt=0,numo=0;
925 char pflname[MED_NAME_SIZE+1]="";
926 char locname[MED_NAME_SIZE+1]="";
927 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
928 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
929 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
932 std::ostringstream oss; oss << "GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
933 std::set<std::string> s2;
934 for(int i=0;i<nbFields;i++)
936 med_int ncomp(MEDfieldnComponent(fid,i+1));
937 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
938 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
940 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
941 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
942 if(curFieldName==fieldName)
945 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
947 for(int k=0;k<nbPdt;k++)
950 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
951 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
952 pflname,&profilesize,locname,&nbi));
953 std::string maa_ass_cpp(maa_ass);
956 if(meshNameCpp==maa_ass_cpp)
959 ret.push_back(std::make_pair(numdt,numo));
962 s2.insert(maa_ass_cpp);
969 oss << "\"" << curFieldName << "\"";
970 if(i!=nbFields-1) oss << ", ";
977 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
978 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
981 throw INTERP_KERNEL::Exception(oss.str().c_str());
986 std::vector< std::pair<int,int> > MEDCoupling::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
988 std::string meshNameCpp(meshName);
989 std::vector< std::pair<int,int> > ret;
990 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
991 med_int nbFields=MEDnField(fid);
993 med_field_type typcha;
994 med_int numdt=0,numo=0;
996 char pflname[MED_NAME_SIZE+1]="";
997 char locname[MED_NAME_SIZE+1]="";
998 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
999 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
1000 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1003 std::ostringstream oss; oss << "GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
1004 std::set<std::string> s2;
1005 for(int i=0;i<nbFields;i++)
1007 med_int ncomp(MEDfieldnComponent(fid,i+1));
1008 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
1009 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1011 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
1012 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1013 if(curFieldName==fieldName)
1015 for(int k=0;k<nbPdt;k++)
1017 int profilesize,nbi;
1018 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
1019 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1020 pflname,&profilesize,locname,&nbi));
1021 std::string maa_ass_cpp(maa_ass);
1024 if(meshNameCpp==maa_ass_cpp)
1025 { ret.push_back(std::make_pair(numdt,numo)); }
1027 s2.insert(maa_ass_cpp);
1033 oss << "\"" << curFieldName << "\"";
1034 if(i!=nbFields-1) oss << ", ";
1041 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1042 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1045 throw INTERP_KERNEL::Exception(oss.str().c_str());
1050 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1052 MEDCoupling::CheckFileForRead(fileName);
1053 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1054 MEDFileMesh *mmPtr(mm);
1055 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1057 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1058 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1061 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1062 return const_cast<MEDCouplingCMesh *>(ret);
1064 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1067 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1068 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1070 std::ostringstream oss; oss << "ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1071 throw INTERP_KERNEL::Exception(oss.str().c_str());
1074 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1076 MEDCoupling::CheckFileForRead(fileName);
1077 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1078 MEDFileMesh *mmPtr(mm);
1079 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1081 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1082 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1085 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1086 return const_cast<MEDCouplingCMesh *>(ret);
1088 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1091 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1092 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1094 std::ostringstream oss; oss << "ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1095 throw INTERP_KERNEL::Exception(oss.str().c_str());
1098 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1100 MEDCoupling::CheckFileForRead(fileName);
1101 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1102 MEDFileMesh *mmPtr(mm);
1103 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1106 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1107 throw INTERP_KERNEL::Exception(oss.str().c_str());
1109 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1112 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1114 MEDCoupling::CheckFileForRead(fileName);
1115 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1116 MEDFileMesh *mmPtr(mm);
1117 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1120 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1121 throw INTERP_KERNEL::Exception(oss.str().c_str());
1123 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1126 int MEDCoupling::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1128 MEDCoupling::CheckFileForRead(fileName);
1129 std::vector<int> poss;
1130 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1133 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1135 MEDCoupling::CheckFileForRead(fileName);
1136 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1137 MEDFileMesh *mmPtr(mm);
1138 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1141 std::ostringstream oss; oss << "ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1142 throw INTERP_KERNEL::Exception(oss.str().c_str());
1144 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1147 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1149 MEDCoupling::CheckFileForRead(fileName);
1150 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1151 MEDFileMesh *mmPtr(mm);
1152 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1155 std::ostringstream oss; oss << "ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1156 throw INTERP_KERNEL::Exception(oss.str().c_str());
1158 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1161 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName)
1163 std::vector<std::string> fieldNames(GetAllFieldNames(fileName));
1164 std::size_t sz(fieldNames.size());
1167 std::ostringstream oss;
1168 oss << "The file \"" << fileName << "\" contains no field !";
1169 throw INTERP_KERNEL::Exception(oss.str());
1173 std::ostringstream oss;
1174 oss << "In file \"" << fileName << "\" there are more than one field !" << std::endl;
1175 oss << "You are invited to use ReadField(fileName, fieldName) instead to avoid misleading concerning field you want to read !" << std::endl;
1176 oss << "For information, fields available are :" << std::endl;
1177 for(std::vector<std::string>::const_iterator it=fieldNames.begin();it!=fieldNames.end();it++)
1178 oss << " - \"" << *it << "\"" << std::endl;
1179 throw INTERP_KERNEL::Exception(oss.str());
1181 return ReadField(fileName,fieldNames[0]);
1184 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName)
1186 std::vector< std::pair< std::pair<int,int>, double> > iterations(GetAllFieldIterations(fileName,fieldName));
1187 std::size_t sz(iterations.size());
1190 std::ostringstream oss;
1191 oss << "In file \"" << fileName << "\" field \"" << fieldName << "\" exists but with no time steps !";
1192 throw INTERP_KERNEL::Exception(oss.str());
1196 std::ostringstream oss;
1197 oss << "In file \"" << fileName << "\" field \"" << fieldName << "\" exists but with more than one time steps !" << std::endl;
1198 oss << "You are invited to use ReadField(fileName, fieldName, iteration, order) instead to avoid misleading concerning time steps." << std::endl;
1199 oss << "For information, time steps available for field \"" << fieldName << "\" are :" << std::endl;
1200 for(std::vector< std::pair< std::pair<int,int>, double> >::const_iterator it=iterations.begin();it!=iterations.end();it++)
1201 oss << " - " << (*it).first.first << ", " << (*it).first.second << " (" << (*it).second << ")" << std::endl;
1202 throw INTERP_KERNEL::Exception(oss.str());
1204 return ReadField(fileName,fieldName,iterations[0].first.first,iterations[0].first.second);
1207 MCAuto<MEDCoupling::MEDCouplingField> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order)
1209 MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
1210 MCAuto<MEDFileMesh> mesh(MEDFileMesh::New(fileName,f->getMeshName()));
1212 MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
1215 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(f1->field(mesh));
1216 return MEDCoupling::DynamicCast<MEDCouplingFieldDouble,MEDCouplingField>(ret);
1220 MCAuto<MEDFileIntField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileIntField1TS>(f));
1223 MCAuto<MEDCoupling::MEDCouplingFieldInt> ret(f1->field(mesh));
1224 return MEDCoupling::DynamicCast<MEDCouplingFieldInt,MEDCouplingField>(ret);
1228 MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
1231 MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(f1->field(mesh));
1232 return MEDCoupling::DynamicCast<MEDCouplingFieldFloat,MEDCouplingField>(ret);
1235 throw INTERP_KERNEL::Exception("MEDCoupling::ReadField : only FLOAT32, FLOAT64 and INT32 supported for the moment !");
1238 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)
1240 MEDCoupling::CheckFileForRead(fileName);
1244 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1246 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1248 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1250 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1252 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1256 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsOnSameMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1257 const std::vector<std::pair<int,int> >& its)
1260 return std::vector<MEDCoupling::MEDCouplingFieldDouble *>();
1261 MEDCoupling::CheckFileForRead(fileName);
1262 std::vector<MEDCoupling::MEDCouplingFieldDouble *> ret(its.size());
1263 std::vector< MCAuto<MEDCouplingFieldDouble> > retSafe(its.size());
1266 //Retrieving mesh of rank 0 and field on rank 0 too.
1267 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1268 MEDFileMesh *mmPtr(mm);
1269 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1271 throw INTERP_KERNEL::Exception("ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1272 MCAuto<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1273 const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1274 MCAuto<MEDCouplingUMesh> m2(m->clone(true));
1276 m2->renumberCells(o2n->begin(),true);
1278 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1280 MCAuto<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1281 MCAuto<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1283 retElt->renumberCells(o2n->begin(),true);
1284 retElt->setMesh(m2);
1288 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1289 ret[i]=retSafe[i].retn();
1293 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1294 const std::vector<std::pair<int,int> >& its)
1296 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1299 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1300 const std::vector<std::pair<int,int> >& its)
1302 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1305 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1306 const std::vector<std::pair<int,int> >& its)
1308 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1311 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1312 const std::vector<std::pair<int,int> >& its)
1314 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1317 namespace MEDCoupling
1320 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)
1322 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1323 MCAuto<MEDFileUMesh> muPtr(MEDCoupling::DynamicCast<MEDFileMesh,MEDFileUMesh>(mm));
1324 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1325 MCAuto<typename Traits<T>::FieldType> ret(ff->getFieldOnMeshAtLevel(type,m));
1326 if(muPtr.isNotNull())
1328 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1330 ret->renumberCells(num->begin());
1335 MEDCoupling::MEDCouplingField *ReadFieldCellLike(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1337 MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
1339 MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
1342 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(ReadFieldCellLikeT<double>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1347 MCAuto<MEDFileIntField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileIntField1TS>(f));
1350 MCAuto<MEDCoupling::MEDCouplingFieldInt> ret(ReadFieldCellLikeT<int>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1355 MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
1358 MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(ReadFieldCellLikeT<float>(f1,type,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1362 throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldCell : only FLOAT32, FLOAT64 and INT32 supported for the moment !");
1366 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)
1368 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1369 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1370 MCAuto<typename Traits<T>::FieldType> ret(ff->getFieldOnMeshAtLevel(ON_NODES,m));
1371 MCAuto<MEDFileUMesh> muPtr(MEDCoupling::DynamicCast<MEDFileMesh,MEDFileUMesh>(mm));
1372 if(ff->getPflsReallyUsed().empty())
1374 if(muPtr.isNotNull())
1376 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1378 ret->renumberCells(num->begin());
1383 DataArrayInt *pfl(nullptr),*arr2(nullptr);
1384 MCAuto<typename Traits<T>::ArrayType> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl));
1385 MCAuto<DataArrayInt> pflSafe(pfl);
1386 MCAuto<DataArrayInt> mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end()));
1387 MCAuto<MEDCouplingUMesh> mzip(static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2)));
1388 MCAuto<DataArrayInt> arr2Safe(arr2);
1389 MCAuto<DataArrayInt> arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes()));
1390 MCAuto<DataArrayInt> pflSorted(pflSafe->deepCopy()); pflSorted->sort(true);
1391 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1392 throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !");
1393 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1395 MCAuto<DataArrayInt> o2n2(pflSafe->checkAndPreparePermutation());
1396 MCAuto<DataArrayInt> n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples()));
1397 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1407 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1409 return ReadFieldCellLike(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1412 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1414 MCAuto<MEDFileAnyTypeField1TS> f(MEDFileAnyTypeField1TS::New(fileName,fieldName,iteration,order));
1416 MCAuto<MEDFileField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileField1TS>(f));
1419 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(ReadFieldNodeT<double>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1424 MCAuto<MEDFileIntField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileIntField1TS>(f));
1427 MCAuto<MEDCoupling::MEDCouplingFieldInt> ret(ReadFieldNodeT<int>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1432 MCAuto<MEDFileFloatField1TS> f1(MEDCoupling::DynamicCast<MEDFileAnyTypeField1TS,MEDFileFloatField1TS>(f));
1435 MCAuto<MEDCoupling::MEDCouplingFieldFloat> ret(ReadFieldNodeT<float>(f1,fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1439 throw INTERP_KERNEL::Exception("MEDCoupling::ReadFieldNode : only FLOAT32, FLOAT64 and INT32 supported for the moment !");
1442 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1444 return ReadFieldCellLike(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1447 MEDCoupling::MEDCouplingField *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1449 return ReadFieldCellLike(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1452 void MEDCoupling::WriteMesh(const std::string& fileName, const MEDCoupling::MEDCouplingMesh *mesh, bool writeFromScratch)
1455 throw INTERP_KERNEL::Exception("WriteMesh : input mesh is null !");
1456 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1459 WriteUMesh(fileName,um,writeFromScratch);
1462 int mod=writeFromScratch?2:0;
1463 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1466 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1467 AssignStaticWritePropertiesTo(*mmu);
1468 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1469 mmu->write(fileName,mod);
1472 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1475 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1476 AssignStaticWritePropertiesTo(*mmc);
1477 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1478 mmc->write(fileName,mod);
1481 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1484 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1485 AssignStaticWritePropertiesTo(*mmc);
1486 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1487 mmc->write(fileName,mod);
1490 throw INTERP_KERNEL::Exception("WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1493 void MEDCoupling::WriteUMesh(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1496 throw INTERP_KERNEL::Exception("WriteUMesh : input mesh is null !");
1497 int mod=writeFromScratch?2:0;
1498 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1499 AssignStaticWritePropertiesTo(*m);
1500 MCAuto<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCopy()));
1501 m->setMeshAtLevel(0,mcpy,true);
1502 m->write(fileName,mod);
1505 void MEDCoupling::WriteUMeshDep(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1507 WriteUMesh(fileName,mesh,writeFromScratch);
1510 void MEDCoupling::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1512 std::string meshName(meshNameC);
1513 if(meshName.empty())
1514 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 !");
1515 int status=MEDLoaderBase::getStatusOfFile(fileName);
1516 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1518 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1519 throw INTERP_KERNEL::Exception(oss.str().c_str());
1521 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1522 AssignStaticWritePropertiesTo(*m);
1523 m->setGroupsFromScratch(0,meshes,true);
1524 m->setName(meshNameC);
1525 int mod=writeFromScratch?2:0;
1526 m->write(fileName,mod);
1529 void MEDCoupling::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1531 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1534 void MEDCoupling::WriteUMeshes(const std::string& fileName, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1536 int mod(writeFromScratch?2:0);
1537 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1538 AssignStaticWritePropertiesTo(*m);
1539 m->setMeshes(meshes,true);
1540 m->write(fileName,mod);
1544 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f, bool writeFromScratch)
1546 MCAuto< typename MLFieldTraits<T>::F1TSType > ff(MLFieldTraits<T>::F1TSType::New());
1547 AssignStaticWritePropertiesTo(*ff);
1548 MCAuto<typename MEDCoupling::Traits<T>::FieldType> f2(f->deepCopy());
1549 const MEDCouplingMesh *m(f2->getMesh());
1550 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1551 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1552 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1553 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1554 MCAuto<MEDFileMesh> mm;
1555 int mod(writeFromScratch?2:0);
1558 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1559 AssignStaticWritePropertiesTo(*mmu);
1560 MCAuto<DataArrayInt> o2n(um->getRenumArrForMEDFileFrmt());
1561 MCAuto<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1562 f2->renumberCells(o2n->begin(),false);
1563 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1564 mmu->setRenumFieldArr(0,n2o);
1565 ff->setFieldNoProfileSBT(f2);
1566 mmu->write(fileName,mod);
1570 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1571 AssignStaticWritePropertiesTo(*mmu);
1572 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1573 ff->setFieldNoProfileSBT(f2);
1574 mmu->write(fileName,mod);
1578 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1579 AssignStaticWritePropertiesTo(*mmc);
1580 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1581 ff->setFieldNoProfileSBT(f2);
1582 mmc->write(fileName,mod);
1586 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1587 AssignStaticWritePropertiesTo(*mmc);
1588 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1589 ff->setFieldNoProfileSBT(f2);
1590 mmc->write(fileName,mod);
1593 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1594 ff->write(fileName,0);
1598 void WriteFieldT(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f, bool writeFromScratch)
1601 throw INTERP_KERNEL::Exception("WriteField : input field is NULL !");
1602 f->checkConsistencyLight();
1603 int status(MEDLoaderBase::getStatusOfFile(fileName));
1604 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1606 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1607 throw INTERP_KERNEL::Exception(oss.str().c_str());
1609 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1611 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile<T>(fileName,f,true);
1615 std::vector<std::string> meshNames(GetMeshNames(fileName));
1617 throw INTERP_KERNEL::Exception("WriteField : trying to write a field with no mesh !");
1618 std::string fileNameCpp(f->getMesh()->getName());
1619 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1620 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile<T>(fileName,f,false);
1623 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1624 AssignStaticWritePropertiesTo(*mm);
1625 const MEDFileMesh *mmPtr(mm);
1626 const MEDFileUMesh *mmuPtr(dynamic_cast<const MEDFileUMesh *>(mmPtr));
1628 throw INTERP_KERNEL::Exception("WriteField : only umeshes are supported now !");
1629 MCAuto< typename MEDCoupling::Traits<T>::FieldType > f2(f->deepCopy());
1630 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh())));
1632 throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !");
1633 MCAuto<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
1634 f2->renumberCells(o2n->begin(),false);
1635 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1636 MCAuto<MEDCouplingUMesh> mread(mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension()));
1637 if(f2->getTypeOfField()!=ON_NODES)
1639 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1640 DataArrayInt *part(NULL);
1641 bool b(mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part));
1642 MCAuto<DataArrayInt> partSafe(part);
1645 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 !";
1646 throw INTERP_KERNEL::Exception(oss.str().c_str());
1648 MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
1649 AssignStaticWritePropertiesTo(*f1ts);
1650 if(part->isIota(mread->getNumberOfCells()))
1651 f1ts->setFieldNoProfileSBT(f2);
1654 part->setName(f1ts->createNewNameOfPfl().c_str());
1655 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1657 f1ts->write(fileName,0);
1662 DataArrayInt *part(NULL);
1663 bool b(mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part));
1664 MCAuto<DataArrayInt> partSafe(part);
1667 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 !";
1668 throw INTERP_KERNEL::Exception(oss.str().c_str());
1670 MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
1671 AssignStaticWritePropertiesTo(*f1ts);
1672 if(part->isIota(mread->getNumberOfNodes()))
1673 f1ts->setFieldNoProfileSBT(f2);
1676 part->setName(f1ts->createNewNameOfPfl().c_str());
1677 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1679 f1ts->write(fileName,0);
1685 void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch)
1688 throw INTERP_KERNEL::Exception("WriteField : input field is null !");
1690 const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldDouble *>(f));
1693 WriteFieldT<double>(fileName,f1,writeFromScratch);
1698 const MEDCoupling::MEDCouplingFieldInt *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt *>(f));
1701 WriteFieldT<int>(fileName,f1,writeFromScratch);
1706 const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldFloat *>(f));
1709 WriteFieldT<float>(fileName,f1,writeFromScratch);
1713 throw INTERP_KERNEL::Exception("WriteField : input field is not in FLOAT32, FLOAT64, INT32 !");
1716 void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingField *f, bool writeFromScratch)
1718 WriteField(fileName,f,writeFromScratch);
1722 void WriteFieldUsingAlreadyWrittenMeshT(const std::string& fileName, const typename MEDCoupling::Traits<T>::FieldType *f)
1725 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMeshT : input field is null !");
1726 f->checkConsistencyLight();
1727 int status(MEDLoaderBase::getStatusOfFile(fileName));
1728 if(status!=MEDLoaderBase::EXIST_RW)
1730 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1731 throw INTERP_KERNEL::Exception(oss.str().c_str());
1733 MCAuto< typename MLFieldTraits<T>::F1TSType > f1ts(MLFieldTraits<T>::F1TSType::New());
1734 AssignStaticWritePropertiesTo(*f1ts);
1735 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1738 MCAuto<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
1739 MCAuto< typename MEDCoupling::Traits<T>::FieldType > f2(f->deepCopy());
1740 f2->renumberCells(o2n->begin(),false);
1741 f1ts->setFieldNoProfileSBT(f2);
1744 f1ts->setFieldNoProfileSBT(f);
1745 f1ts->write(fileName,0);
1748 void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingField *f)
1751 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1753 const MEDCoupling::MEDCouplingFieldDouble *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldDouble *>(f));
1755 WriteFieldUsingAlreadyWrittenMeshT<double>(fileName,f1);
1759 const MEDCoupling::MEDCouplingFieldInt *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldInt *>(f));
1761 WriteFieldUsingAlreadyWrittenMeshT<int>(fileName,f1);
1765 const MEDCoupling::MEDCouplingFieldFloat *f1(dynamic_cast<const MEDCoupling::MEDCouplingFieldFloat *>(f));
1767 WriteFieldUsingAlreadyWrittenMeshT<float>(fileName,f1);
1770 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is not in FLOAT32, FLOAT64, INT32 !");