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 "MEDCouplingGaussLocalization.hxx"
35 #include "InterpKernelAutoPtr.hxx"
49 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
73 med_geometry_type typmainoeud[1] = { MED_NONE };
75 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
76 INTERP_KERNEL::NORM_SEG2,
77 INTERP_KERNEL::NORM_SEG3,
78 INTERP_KERNEL::NORM_SEG4,
79 INTERP_KERNEL::NORM_TRI3,
80 INTERP_KERNEL::NORM_QUAD4,
81 INTERP_KERNEL::NORM_TRI6,
82 INTERP_KERNEL::NORM_TRI7,
83 INTERP_KERNEL::NORM_QUAD8,
84 INTERP_KERNEL::NORM_QUAD9,
85 INTERP_KERNEL::NORM_TETRA4,
86 INTERP_KERNEL::NORM_PYRA5,
87 INTERP_KERNEL::NORM_PENTA6,
88 INTERP_KERNEL::NORM_HEXA8,
89 INTERP_KERNEL::NORM_HEXGP12,
90 INTERP_KERNEL::NORM_TETRA10,
91 INTERP_KERNEL::NORM_PYRA13,
92 INTERP_KERNEL::NORM_PENTA15,
93 INTERP_KERNEL::NORM_HEXA20,
94 INTERP_KERNEL::NORM_HEXA27,
95 INTERP_KERNEL::NORM_POLYGON,
96 INTERP_KERNEL::NORM_QPOLYG,
97 INTERP_KERNEL::NORM_POLYHED };
99 med_geometry_type typmai3[34] = { MED_POINT1,//0
135 double _EPS_FOR_NODE_COMP=1.e-12;
137 int _COMP_FOR_CELL=0;
141 using namespace MEDCoupling;
146 * This method returns a first quick overview of mesh with name \a meshName into the file \a fileName.
147 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
148 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
150 int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities)
152 possibilities.clear();
153 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
156 char nommaa[MED_NAME_SIZE+1];
157 char maillage_description[MED_COMMENT_SIZE+1];
158 med_mesh_type type_maillage;
160 std::string trueMeshName;
161 med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
162 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
163 med_sorting_type sortingType;
165 med_axis_type axisType;
166 int naxis(MEDmeshnAxis(fid,meshId));
167 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
168 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
169 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
173 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
177 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
179 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
181 med_geometry_type curMedType=typmai[i];
182 med_bool changement,transformation;
183 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
184 int curNbOfElemF(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));//limitation
186 med_entity_type whichEntity;
187 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
190 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
191 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
198 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
199 possibilities.push_back(*it-ret);
206 med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName)
210 std::vector<std::string> meshes=getMeshNamesFid(fid);
212 throw INTERP_KERNEL::Exception("No mesh in file");
213 trueMeshName=meshes[0];
216 std::string meshNameStr(meshName);
217 std::vector<std::string> meshes=getMeshNamesFid(fid);
219 throw INTERP_KERNEL::Exception("No mesh in file");
220 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
221 if(iter==meshes.end())
223 std::ostringstream os2;
224 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
225 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
226 throw INTERP_KERNEL::Exception(os2.str().c_str());
228 trueMeshName=meshName;
229 return iter-meshes.begin()+1;
232 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
234 med_mesh_type type_maillage;
235 char maillage_description[MED_COMMENT_SIZE+1];
236 char dtunit[MED_COMMENT_SIZE+1];
239 char nommaa[MED_NAME_SIZE+1];
240 med_axis_type axistype;
241 med_sorting_type stype;
242 med_int n=MEDnMesh(fid);
243 std::vector<std::string> ret(n);
246 int naxis(MEDmeshnAxis(fid,i+1));
247 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
248 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
250 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
251 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
258 * This methods allows to merger all entities and to considerate only cell types.
260 void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
262 if(nbOfElemCell>=nbOfElemFace)
264 whichEntity=MED_CELL;
265 nbOfElem=nbOfElemCell;
269 whichEntity=MED_CELL;
270 nbOfElem=nbOfElemFace;
276 void MEDCoupling::AssignStaticWritePropertiesTo(MEDCoupling::MEDFileWritable& obj)
278 obj.setTooLongStrPolicy(_TOO_LONG_STR);
281 bool MEDCoupling::HasXDR()
290 std::string MEDCoupling::MEDFileVersionStr()
292 return std::string(MED_VERSION_STR);
295 std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
297 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
299 const char START_EXPECTED[]="MED-";
301 std::fill(buf,buf+SZ,'\0');
302 MEDFILESAFECALLERRD0(MEDfileStrVersionRd,(fid,buf));
303 std::string ret(buf);
304 std::size_t pos(ret.find(START_EXPECTED,0));
307 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : internal error ! The MEDFile returned version (\"" << ret << "\") has not the right pattern !";
308 throw INTERP_KERNEL::Exception(oss.str());
310 return ret.substr(sizeof(START_EXPECTED)-1,std::string::npos);
313 void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
315 major=MED_NUM_MAJEUR;
316 minor=MED_NUM_MINEUR;
317 release=MED_NUM_RELEASE;
321 * This method sets the epsilon value used for node comparison when trying to buid a profile for a field on node/cell on an already written mesh.
323 void MEDCoupling::SetEpsilonForNodeComp(double val)
325 _EPS_FOR_NODE_COMP=val;
329 * 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.
331 void MEDCoupling::SetCompPolicyForCell(int val)
337 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
338 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
340 void MEDCoupling::SetTooLongStrPolicy(int val)
346 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
347 * It returns, in this order :
348 * - 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...
349 * - the mesh dimension
350 * - the space dimension
351 * - the number of nodes
353 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)
355 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
357 char nommaa[MED_NAME_SIZE+1];
358 char maillage_description[MED_COMMENT_SIZE+1];
359 med_mesh_type type_maillage;
360 std::string trueMeshName;
361 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
362 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
363 med_sorting_type sortingType;
365 med_axis_type axisType;
366 int naxis(MEDmeshnAxis(fid,meshId));
367 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
368 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
369 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
370 if(type_maillage!=MED_UNSTRUCTURED_MESH)
372 std::ostringstream oss; oss << "GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
373 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
374 throw INTERP_KERNEL::Exception(oss.str().c_str());
378 throw INTERP_KERNEL::Exception("GetUMeshGlobalInfo : multisteps on mesh not managed !");
381 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
383 std::vector<int> dims;
384 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
385 med_bool changement,transformation;
386 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
388 med_geometry_type curMedType=typmai[i];
389 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
392 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
393 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
394 dims.push_back(mdimCell);
395 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
398 int maxLev=*std::max_element(dims.begin(),dims.end());
399 int lowLev=*std::min_element(dims.begin(),dims.end());
400 int nbOfLevels=maxLev-lowLev+1;
401 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
402 for(std::size_t i=0;i<dims.size();i++)
404 ret[maxLev-dims[i]].push_back(geoTypes[i]);
406 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
410 void MEDCoupling::CheckFileForRead(const std::string& fileName)
412 MEDFileUtilities::CheckFileForRead(fileName);
415 std::vector<std::string> MEDCoupling::GetMeshNames(const std::string& fileName)
417 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
418 return MEDLoaderNS::getMeshNamesFid(fid);
421 std::vector< std::pair<std::string,std::string> > MEDCoupling::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
423 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
424 med_int nbFields(MEDnField(fid));
425 std::vector<std::string> fields(nbFields);
426 med_field_type typcha;
427 for(int i=0;i<nbFields;i++)
429 med_int ncomp(MEDfieldnComponent(fid,i+1));
430 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
431 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
432 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
435 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
436 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
437 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
438 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
439 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
440 if(curFieldName==fieldName)
442 std::vector< std::pair<std::string,std::string> > ret(ncomp);
443 for(int j=0;j<ncomp;j++)
444 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
445 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
448 fields[i]=curFieldName;
450 std::ostringstream oss; oss << "GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
451 oss << "Possible field names are : " << std::endl;
452 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
453 throw INTERP_KERNEL::Exception(oss.str().c_str());
456 std::vector<std::string> MEDCoupling::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
458 std::vector<std::string> ret;
460 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
461 med_int nbFields=MEDnField(fid);
463 med_field_type typcha;
464 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
465 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
468 for(int i=0;i<nbFields;i++)
470 med_int ncomp(MEDfieldnComponent(fid,i+1));
471 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
472 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
474 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
475 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
476 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
477 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
478 if(curFieldName==fieldName)
479 ret.push_back(meshName);
484 std::vector<std::string> MEDCoupling::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
486 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
487 med_int nfam=MEDnFamily(fid,meshName.c_str());
488 std::vector<std::string> ret(nfam);
489 char nomfam[MED_NAME_SIZE+1];
491 for(int i=0;i<nfam;i++)
493 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
494 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
495 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
496 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
497 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
498 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
499 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
500 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
507 std::vector<std::string> MEDCoupling::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
509 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
510 med_int nfam=MEDnFamily(fid,meshName.c_str());
511 std::vector<std::string> ret;
512 char nomfam[MED_NAME_SIZE+1];
514 for(int i=0;i<nfam;i++)
516 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
517 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
518 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
519 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
520 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
521 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
522 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
523 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
524 for(int j=0;j<ngro;j++)
526 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
534 std::vector<std::string> MEDCoupling::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
536 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
537 med_int nfam(MEDnFamily(fid,meshName.c_str()));
538 std::vector<std::string> ret;
539 char nomfam[MED_NAME_SIZE+1];
542 for(int i=0;i<nfam && !found;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 found=(cur==famName);
554 for(int j=0;j<ngro;j++)
556 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
562 std::ostringstream oss;
563 oss << "GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
564 throw INTERP_KERNEL::Exception(oss.str().c_str());
570 std::vector<std::string> MEDCoupling::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
572 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
573 med_int nfam=MEDnFamily(fid,meshName.c_str());
574 std::vector<std::string> ret;
575 char nomfam[MED_NAME_SIZE+1];
577 for(int i=0;i<nfam;i++)
579 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
580 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
581 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
582 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
583 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
584 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
585 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
586 for(int j=0;j<ngro;j++)
588 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
589 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
596 std::vector<MEDCoupling::TypeOfField> MEDCoupling::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
598 std::vector<MEDCoupling::TypeOfField> ret;
599 MCAuto<MEDFileAnyTypeFieldMultiTS> fs(MEDFileAnyTypeFieldMultiTS::New(fileName,fieldName,false));
600 if(fs->getMeshName()!=meshName)
602 std::ostringstream oss; oss << "GetTypesOfField : The field \"" << fieldName << "\" in file \"" << fileName << "\" is not lying on mesh \"" << meshName << "\"";
603 oss << " The name of the mesh in file is \"" << fs->getMeshName() << "\"!";
604 throw INTERP_KERNEL::Exception(oss.str().c_str());
606 int nbTS(fs->getNumberOfTS());
609 for(int i=0;i<nbTS;i++)
611 MCAuto<MEDFileAnyTypeField1TS> f1ts(fs->getTimeStepAtPos(i));
612 std::vector<MEDCoupling::TypeOfField> tof(f1ts->getTypesOfFieldAvailable());
613 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=tof.begin();it!=tof.end();it++)
614 if(std::find(ret.begin(),ret.end(),*it)==ret.end())
617 // sort ret to put before ON_NODES then ON_CELLS then the remaining.
618 std::vector<MEDCoupling::TypeOfField> ret2;
619 if(std::find(ret.begin(),ret.end(),ON_NODES)!=ret.end())
620 ret2.push_back(ON_NODES);
621 if(std::find(ret.begin(),ret.end(),ON_CELLS)!=ret.end())
622 ret2.push_back(ON_CELLS);
623 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=ret.begin();it!=ret.end();it++)
624 if(*it!=ON_NODES && *it!=ON_CELLS)
629 std::vector<std::string> MEDCoupling::GetAllFieldNames(const std::string& fileName)
631 std::vector<std::string> ret;
632 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
633 med_int nbFields=MEDnField(fid);
634 med_field_type typcha;
635 for(int i=0;i<nbFields;i++)
637 med_int ncomp(MEDfieldnComponent(fid,i+1));
638 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
639 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
640 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
641 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
642 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
645 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
646 ret.push_back(std::string(nomcha));
651 std::vector<std::string> MEDCoupling::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
653 std::vector<std::string> ret;
654 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
655 med_int nbFields=MEDnField(fid);
657 med_field_type typcha;
658 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
659 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
661 for(int i=0;i<nbFields;i++)
663 med_int ncomp(MEDfieldnComponent(fid,i+1));
664 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
665 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
666 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
669 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
670 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
671 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
673 if(curMeshName==meshName)
674 ret.push_back(curFieldName);
681 std::vector<std::string> MEDCoupling::GetFieldNamesOnMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName)
683 MEDCoupling::CheckFileForRead(fileName);
687 return GetCellFieldNamesOnMesh(fileName,meshName);
689 return GetNodeFieldNamesOnMesh(fileName,meshName);
691 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
695 std::vector<std::string> MEDCoupling::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
697 std::vector<std::string> ret;
698 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
699 med_int nbFields=MEDnField(fid);
701 med_field_type typcha;
702 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
703 med_int numdt=0,numo=0;
705 char pflname[MED_NAME_SIZE+1]="";
706 char locname[MED_NAME_SIZE+1]="";
707 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
708 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
709 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
713 for(int i=0;i<nbFields;i++)
715 med_int ncomp(MEDfieldnComponent(fid,i+1));
716 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
717 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
718 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
719 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
720 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
722 if(curMeshName==meshName)
725 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
729 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
730 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
731 pflname,&profilesize,locname,&nbi));
735 ret.push_back(curFieldName);
744 std::vector<std::string> MEDCoupling::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
746 std::vector<std::string> ret;
747 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
748 med_int nbFields=MEDnField(fid);
749 char pflname[MED_NAME_SIZE+1]="";
750 char locname[MED_NAME_SIZE+1]="";
752 med_field_type typcha;
753 med_int numdt=0,numo=0;
755 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
756 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
757 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
760 for(int i=0;i<nbFields;i++)
762 med_int ncomp(MEDfieldnComponent(fid,i+1));
763 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
764 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
766 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
767 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
768 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
772 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
773 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
774 pflname,&profilesize,locname,&nbi));
775 if(curMeshName==meshName && nbOfVal>0)
777 ret.push_back(curFieldName);
784 std::vector< std::pair< std::pair<int,int>, double> > MEDCoupling::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
786 std::vector< std::pair< std::pair<int,int>, double > > ret;
787 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
788 med_int nbFields=MEDnField(fid);
790 med_field_type typcha;
791 med_int numdt=0,numo=0;
793 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
794 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
795 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
798 std::ostringstream oss; oss << "GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
799 for(int i=0;i<nbFields;i++)
801 med_int ncomp(MEDfieldnComponent(fid,i+1));
802 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
803 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
805 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
806 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
807 if(curFieldName==fieldName)
809 for(int k=0;k<nbPdt;k++)
811 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
812 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
818 oss << "\"" << curFieldName << "\"";
819 if(i!=nbFields-1) oss << ", ";
823 throw INTERP_KERNEL::Exception(oss.str().c_str());
826 double MEDCoupling::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
828 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
829 med_int nbFields=MEDnField(fid);
831 med_field_type typcha;
832 med_int numdt=0,numo=0;
835 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
836 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
837 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
841 double ret=std::numeric_limits<double>::max();
842 for(int i=0;i<nbFields && !found;i++)
844 med_int ncomp(MEDfieldnComponent(fid,i+1));
845 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
846 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
848 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt));
849 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
850 if(curFieldName==fieldName)
853 for(int k=0;k<nbPdt;k++)
855 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
856 if(numdt==iteration && numo==order)
864 if(!found || !found2)
866 std::ostringstream oss;
867 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
868 throw INTERP_KERNEL::Exception(oss.str().c_str());
873 std::vector< std::pair<int,int> > MEDCoupling::GetFieldIterations(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
875 MEDCoupling::CheckFileForRead(fileName);
879 return GetCellFieldIterations(fileName,meshName,fieldName);
881 return GetNodeFieldIterations(fileName,meshName,fieldName);
883 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
887 std::vector< std::pair<int,int> > MEDCoupling::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
889 std::string meshNameCpp(meshName);
890 std::vector< std::pair<int,int> > ret;
891 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
892 med_int nbFields=MEDnField(fid);
894 med_field_type typcha;
895 med_int numdt=0,numo=0;
897 char pflname[MED_NAME_SIZE+1]="";
898 char locname[MED_NAME_SIZE+1]="";
899 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
900 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
901 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
904 std::ostringstream oss; oss << "GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
905 std::set<std::string> s2;
906 for(int i=0;i<nbFields;i++)
908 med_int ncomp(MEDfieldnComponent(fid,i+1));
909 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
910 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
912 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
913 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
914 if(curFieldName==fieldName)
917 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
919 for(int k=0;k<nbPdt;k++)
922 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
923 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
924 pflname,&profilesize,locname,&nbi));
925 std::string maa_ass_cpp(maa_ass);
928 if(meshNameCpp==maa_ass_cpp)
931 ret.push_back(std::make_pair(numdt,numo));
934 s2.insert(maa_ass_cpp);
941 oss << "\"" << curFieldName << "\"";
942 if(i!=nbFields-1) oss << ", ";
949 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
950 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
953 throw INTERP_KERNEL::Exception(oss.str().c_str());
958 std::vector< std::pair<int,int> > MEDCoupling::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
960 std::string meshNameCpp(meshName);
961 std::vector< std::pair<int,int> > ret;
962 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
963 med_int nbFields=MEDnField(fid);
965 med_field_type typcha;
966 med_int numdt=0,numo=0;
968 char pflname[MED_NAME_SIZE+1]="";
969 char locname[MED_NAME_SIZE+1]="";
970 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
971 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
972 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
975 std::ostringstream oss; oss << "GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
976 std::set<std::string> s2;
977 for(int i=0;i<nbFields;i++)
979 med_int ncomp(MEDfieldnComponent(fid,i+1));
980 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
981 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
983 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
984 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
985 if(curFieldName==fieldName)
987 for(int k=0;k<nbPdt;k++)
990 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
991 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
992 pflname,&profilesize,locname,&nbi));
993 std::string maa_ass_cpp(maa_ass);
996 if(meshNameCpp==maa_ass_cpp)
997 { ret.push_back(std::make_pair(numdt,numo)); }
999 s2.insert(maa_ass_cpp);
1005 oss << "\"" << curFieldName << "\"";
1006 if(i!=nbFields-1) oss << ", ";
1013 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1014 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1017 throw INTERP_KERNEL::Exception(oss.str().c_str());
1022 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1024 MEDCoupling::CheckFileForRead(fileName);
1025 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1026 MEDFileMesh *mmPtr(mm);
1027 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1029 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1030 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1033 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1034 return const_cast<MEDCouplingCMesh *>(ret);
1036 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1039 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1040 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1042 std::ostringstream oss; oss << "ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1043 throw INTERP_KERNEL::Exception(oss.str().c_str());
1046 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1048 MEDCoupling::CheckFileForRead(fileName);
1049 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1050 MEDFileMesh *mmPtr(mm);
1051 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1053 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1054 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1057 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1058 return const_cast<MEDCouplingCMesh *>(ret);
1060 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1063 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1064 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1066 std::ostringstream oss; oss << "ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1067 throw INTERP_KERNEL::Exception(oss.str().c_str());
1070 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1072 MEDCoupling::CheckFileForRead(fileName);
1073 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1074 MEDFileMesh *mmPtr(mm);
1075 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1078 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1079 throw INTERP_KERNEL::Exception(oss.str().c_str());
1081 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1084 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1086 MEDCoupling::CheckFileForRead(fileName);
1087 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1088 MEDFileMesh *mmPtr(mm);
1089 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1092 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1093 throw INTERP_KERNEL::Exception(oss.str().c_str());
1095 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1098 int MEDCoupling::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1100 MEDCoupling::CheckFileForRead(fileName);
1101 std::vector<int> poss;
1102 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1105 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1107 MEDCoupling::CheckFileForRead(fileName);
1108 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1109 MEDFileMesh *mmPtr(mm);
1110 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1113 std::ostringstream oss; oss << "ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1114 throw INTERP_KERNEL::Exception(oss.str().c_str());
1116 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1119 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1121 MEDCoupling::CheckFileForRead(fileName);
1122 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1123 MEDFileMesh *mmPtr(mm);
1124 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1127 std::ostringstream oss; oss << "ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1128 throw INTERP_KERNEL::Exception(oss.str().c_str());
1130 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1133 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadField(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1135 MEDCoupling::CheckFileForRead(fileName);
1139 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1141 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1143 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1145 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1147 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1151 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsOnSameMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1152 const std::vector<std::pair<int,int> >& its)
1155 return std::vector<MEDCoupling::MEDCouplingFieldDouble *>();
1156 MEDCoupling::CheckFileForRead(fileName);
1157 std::vector<MEDCoupling::MEDCouplingFieldDouble *> ret(its.size());
1158 std::vector< MCAuto<MEDCouplingFieldDouble> > retSafe(its.size());
1161 //Retrieving mesh of rank 0 and field on rank 0 too.
1162 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1163 MEDFileMesh *mmPtr(mm);
1164 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1166 throw INTERP_KERNEL::Exception("ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1167 MCAuto<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1168 const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1169 MCAuto<MEDCouplingUMesh> m2(m->clone(true));
1171 m2->renumberCells(o2n->begin(),true);
1173 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1175 MCAuto<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1176 MCAuto<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1178 retElt->renumberCells(o2n->begin(),true);
1179 retElt->setMesh(m2);
1183 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1184 ret[i]=retSafe[i].retn();
1188 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1189 const std::vector<std::pair<int,int> >& its)
1191 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1194 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1195 const std::vector<std::pair<int,int> >& its)
1197 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1200 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1201 const std::vector<std::pair<int,int> >& its)
1203 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1206 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1207 const std::vector<std::pair<int,int> >& its)
1209 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1212 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1214 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1215 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1216 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1217 MEDFileMesh *mPtr(mm);
1218 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1219 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_CELLS,m));
1222 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1224 ret->renumberCells(num->begin());
1229 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1231 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1232 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1233 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1234 MEDFileMesh *mPtr(mm);
1235 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_NODES,m));
1236 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1237 if(ff->getPflsReallyUsed().empty())
1241 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1243 ret->renumberCells(num->begin());
1248 DataArrayInt *pfl=0,*arr2=0;
1249 MCAuto<DataArrayDouble> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl));
1250 MCAuto<DataArrayInt> pflSafe(pfl);
1251 MCAuto<DataArrayInt> mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end()));
1252 MCAuto<MEDCouplingUMesh> mzip(static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2)));
1253 MCAuto<DataArrayInt> arr2Safe(arr2);
1254 MCAuto<DataArrayInt> arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes()));
1255 MCAuto<DataArrayInt> pflSorted(pflSafe->deepCopy()); pflSorted->sort(true);
1256 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1257 throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !");
1258 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1260 MCAuto<DataArrayInt> o2n2(pflSafe->checkAndPreparePermutation());
1261 MCAuto<DataArrayInt> n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples()));
1262 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1271 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1273 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1274 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1275 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1276 MEDFileMesh *mPtr(mm);
1277 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1278 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m));
1281 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1283 ret->renumberCells(num->begin());
1288 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1290 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1291 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1292 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1293 MEDFileMesh *mPtr(mm);
1294 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1295 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m));
1298 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1300 ret->renumberCells(num->begin());
1305 void MEDCoupling::WriteMesh(const std::string& fileName, const MEDCoupling::MEDCouplingMesh *mesh, bool writeFromScratch)
1308 throw INTERP_KERNEL::Exception("WriteMesh : input mesh is null !");
1309 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1312 WriteUMesh(fileName,um,writeFromScratch);
1315 int mod=writeFromScratch?2:0;
1316 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1319 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1320 AssignStaticWritePropertiesTo(*mmu);
1321 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1322 mmu->write(fileName,mod);
1325 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1328 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1329 AssignStaticWritePropertiesTo(*mmc);
1330 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1331 mmc->write(fileName,mod);
1334 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1337 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1338 AssignStaticWritePropertiesTo(*mmc);
1339 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1340 mmc->write(fileName,mod);
1343 throw INTERP_KERNEL::Exception("WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1346 void MEDCoupling::WriteUMesh(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1349 throw INTERP_KERNEL::Exception("WriteUMesh : input mesh is null !");
1350 int mod=writeFromScratch?2:0;
1351 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1352 AssignStaticWritePropertiesTo(*m);
1353 MCAuto<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCopy()));
1354 m->setMeshAtLevel(0,mcpy,true);
1355 m->write(fileName,mod);
1358 void MEDCoupling::WriteUMeshDep(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1360 WriteUMesh(fileName,mesh,writeFromScratch);
1363 void MEDCoupling::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1365 std::string meshName(meshNameC);
1366 if(meshName.empty())
1367 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 !");
1368 int status=MEDLoaderBase::getStatusOfFile(fileName);
1369 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1371 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1372 throw INTERP_KERNEL::Exception(oss.str().c_str());
1374 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1375 AssignStaticWritePropertiesTo(*m);
1376 m->setGroupsFromScratch(0,meshes,true);
1377 m->setName(meshNameC);
1378 int mod=writeFromScratch?2:0;
1379 m->write(fileName,mod);
1382 void MEDCoupling::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1384 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1387 void MEDCoupling::WriteUMeshes(const std::string& fileName, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1389 int mod=writeFromScratch?2:0;
1390 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1391 AssignStaticWritePropertiesTo(*m);
1392 m->setMeshes(meshes,true);
1393 m->write(fileName,mod);
1396 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1398 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New());
1399 AssignStaticWritePropertiesTo(*ff);
1400 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1401 const MEDCouplingMesh *m(f2->getMesh());
1402 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1403 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1404 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1405 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1406 MCAuto<MEDFileMesh> mm;
1407 int mod=writeFromScratch?2:0;
1410 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1411 AssignStaticWritePropertiesTo(*mmu);
1412 MCAuto<DataArrayInt> o2n(um->getRenumArrForMEDFileFrmt());
1413 MCAuto<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1414 f2->renumberCells(o2n->begin(),false);
1415 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1416 mmu->setRenumFieldArr(0,n2o);
1417 ff->setFieldNoProfileSBT(f2);
1418 mmu->write(fileName,mod);
1422 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1423 AssignStaticWritePropertiesTo(*mmu);
1424 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1425 ff->setFieldNoProfileSBT(f2);
1426 mmu->write(fileName,mod);
1430 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1431 AssignStaticWritePropertiesTo(*mmc);
1432 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1433 ff->setFieldNoProfileSBT(f2);
1434 mmc->write(fileName,mod);
1438 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1439 AssignStaticWritePropertiesTo(*mmc);
1440 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1441 ff->setFieldNoProfileSBT(f2);
1442 mmc->write(fileName,mod);
1445 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1446 ff->write(fileName,0);
1449 void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1452 throw INTERP_KERNEL::Exception("WriteField : input field is NULL !");
1453 f->checkConsistencyLight();
1454 int status=MEDLoaderBase::getStatusOfFile(fileName);
1455 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1457 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1458 throw INTERP_KERNEL::Exception(oss.str().c_str());
1460 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1462 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
1466 std::vector<std::string> meshNames=GetMeshNames(fileName);
1468 throw INTERP_KERNEL::Exception("WriteField : trying to write a field with no mesh !");
1469 std::string fileNameCpp(f->getMesh()->getName());
1470 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1471 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
1474 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1475 AssignStaticWritePropertiesTo(*mm);
1476 const MEDFileMesh *mmPtr(mm);
1477 const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
1479 throw INTERP_KERNEL::Exception("WriteField : only umeshes are supported now !");
1480 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1481 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1483 throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !");
1484 MCAuto<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1485 f2->renumberCells(o2n->begin(),false);
1486 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1487 MCAuto<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
1488 if(f2->getTypeOfField()!=ON_NODES)
1490 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1491 DataArrayInt *part=0;
1492 bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
1493 MCAuto<DataArrayInt> partSafe(part);
1496 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 !";
1497 throw INTERP_KERNEL::Exception(oss.str().c_str());
1499 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1500 AssignStaticWritePropertiesTo(*f1ts);
1501 if(part->isIota(mread->getNumberOfCells()))
1502 f1ts->setFieldNoProfileSBT(f2);
1505 part->setName(f1ts->createNewNameOfPfl().c_str());
1506 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1508 f1ts->write(fileName,0);
1513 DataArrayInt *part=0;
1514 bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
1515 MCAuto<DataArrayInt> partSafe(part);
1518 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 !";
1519 throw INTERP_KERNEL::Exception(oss.str().c_str());
1521 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1522 AssignStaticWritePropertiesTo(*f1ts);
1523 if(part->isIota(mread->getNumberOfNodes()))
1524 f1ts->setFieldNoProfileSBT(f2);
1527 part->setName(f1ts->createNewNameOfPfl().c_str());
1528 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1530 f1ts->write(fileName,0);
1536 void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1538 WriteField(fileName,f,writeFromScratch);
1541 void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f)
1544 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1545 f->checkConsistencyLight();
1546 int status=MEDLoaderBase::getStatusOfFile(fileName);
1547 if(status!=MEDLoaderBase::EXIST_RW)
1549 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1550 throw INTERP_KERNEL::Exception(oss.str().c_str());
1552 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1553 AssignStaticWritePropertiesTo(*f1ts);
1554 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1557 MCAuto<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
1558 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1559 f2->renumberCells(o2n->begin(),false);
1560 f1ts->setFieldNoProfileSBT(f2);
1563 f1ts->setFieldNoProfileSBT(f);
1564 f1ts->write(fileName,0);