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 #if MED_NUM_MAJEUR>=3 && MED_NUM_MINEUR>=2 && MED_NUM_RELEASE>=1
298 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
300 const char START_EXPECTED[]="MED-";
302 std::fill(buf,buf+SZ,'\0');
303 MEDFILESAFECALLERRD0(MEDfileStrVersionRd,(fid,buf));
304 std::string ret(buf);
305 std::size_t pos(ret.find(START_EXPECTED,0));
308 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : internal error ! The MEDFile returned version (\"" << ret << "\") has not the right pattern !";
309 throw INTERP_KERNEL::Exception(oss.str());
311 return ret.substr(sizeof(START_EXPECTED)-1,std::string::npos);
313 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : is implemented with MEDFile " << MEDFileVersionStr() << " ! If you need this feature please use version >= 3.2.1.";
314 throw INTERP_KERNEL::Exception(oss.str());
318 void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
320 major=MED_NUM_MAJEUR;
321 minor=MED_NUM_MINEUR;
322 release=MED_NUM_RELEASE;
326 * 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.
328 void MEDCoupling::SetEpsilonForNodeComp(double val)
330 _EPS_FOR_NODE_COMP=val;
334 * 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.
336 void MEDCoupling::SetCompPolicyForCell(int val)
342 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
343 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
345 void MEDCoupling::SetTooLongStrPolicy(int val)
351 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
352 * It returns, in this order :
353 * - 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...
354 * - the mesh dimension
355 * - the space dimension
356 * - the number of nodes
358 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)
360 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
362 char nommaa[MED_NAME_SIZE+1];
363 char maillage_description[MED_COMMENT_SIZE+1];
364 med_mesh_type type_maillage;
365 std::string trueMeshName;
366 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
367 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
368 med_sorting_type sortingType;
370 med_axis_type axisType;
371 int naxis(MEDmeshnAxis(fid,meshId));
372 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
373 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
374 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
375 if(type_maillage!=MED_UNSTRUCTURED_MESH)
377 std::ostringstream oss; oss << "GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
378 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
379 throw INTERP_KERNEL::Exception(oss.str().c_str());
383 throw INTERP_KERNEL::Exception("GetUMeshGlobalInfo : multisteps on mesh not managed !");
386 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
388 std::vector<int> dims;
389 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
390 med_bool changement,transformation;
391 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
393 med_geometry_type curMedType=typmai[i];
394 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
397 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
398 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
399 dims.push_back(mdimCell);
400 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
403 int maxLev=*std::max_element(dims.begin(),dims.end());
404 int lowLev=*std::min_element(dims.begin(),dims.end());
405 int nbOfLevels=maxLev-lowLev+1;
406 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
407 for(std::size_t i=0;i<dims.size();i++)
409 ret[maxLev-dims[i]].push_back(geoTypes[i]);
411 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
415 void MEDCoupling::CheckFileForRead(const std::string& fileName)
417 MEDFileUtilities::CheckFileForRead(fileName);
420 std::vector<std::string> MEDCoupling::GetMeshNames(const std::string& fileName)
422 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
423 return MEDLoaderNS::getMeshNamesFid(fid);
426 std::vector< std::pair<std::string,std::string> > MEDCoupling::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
428 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
429 med_int nbFields(MEDnField(fid));
430 std::vector<std::string> fields(nbFields);
431 med_field_type typcha;
432 for(int i=0;i<nbFields;i++)
434 med_int ncomp(MEDfieldnComponent(fid,i+1));
435 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
436 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
437 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
440 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
441 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
442 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
443 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
444 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
445 if(curFieldName==fieldName)
447 std::vector< std::pair<std::string,std::string> > ret(ncomp);
448 for(int j=0;j<ncomp;j++)
449 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
450 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
453 fields[i]=curFieldName;
455 std::ostringstream oss; oss << "GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
456 oss << "Possible field names are : " << std::endl;
457 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
458 throw INTERP_KERNEL::Exception(oss.str().c_str());
461 std::vector<std::string> MEDCoupling::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
463 std::vector<std::string> ret;
465 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
466 med_int nbFields=MEDnField(fid);
468 med_field_type typcha;
469 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
470 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
473 for(int i=0;i<nbFields;i++)
475 med_int ncomp(MEDfieldnComponent(fid,i+1));
476 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
477 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
479 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
480 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
481 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
482 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
483 if(curFieldName==fieldName)
484 ret.push_back(meshName);
489 std::vector<std::string> MEDCoupling::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
491 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
492 med_int nfam=MEDnFamily(fid,meshName.c_str());
493 std::vector<std::string> ret(nfam);
494 char nomfam[MED_NAME_SIZE+1];
496 for(int i=0;i<nfam;i++)
498 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
499 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
500 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
501 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
502 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
503 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
504 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
505 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
512 std::vector<std::string> MEDCoupling::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
514 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
515 med_int nfam=MEDnFamily(fid,meshName.c_str());
516 std::vector<std::string> ret;
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));
529 for(int j=0;j<ngro;j++)
531 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
539 std::vector<std::string> MEDCoupling::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
541 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
542 med_int nfam(MEDnFamily(fid,meshName.c_str()));
543 std::vector<std::string> ret;
544 char nomfam[MED_NAME_SIZE+1];
547 for(int i=0;i<nfam && !found;i++)
549 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
550 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
551 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
552 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
553 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
554 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
555 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
556 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
557 found=(cur==famName);
559 for(int j=0;j<ngro;j++)
561 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
567 std::ostringstream oss;
568 oss << "GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
569 throw INTERP_KERNEL::Exception(oss.str().c_str());
575 std::vector<std::string> MEDCoupling::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
577 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
578 med_int nfam=MEDnFamily(fid,meshName.c_str());
579 std::vector<std::string> ret;
580 char nomfam[MED_NAME_SIZE+1];
582 for(int i=0;i<nfam;i++)
584 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
585 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
586 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
587 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
588 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
589 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
590 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
591 for(int j=0;j<ngro;j++)
593 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
594 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
601 std::vector<MEDCoupling::TypeOfField> MEDCoupling::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
603 std::vector<MEDCoupling::TypeOfField> ret;
604 MCAuto<MEDFileAnyTypeFieldMultiTS> fs(MEDFileAnyTypeFieldMultiTS::New(fileName,fieldName,false));
605 if(fs->getMeshName()!=meshName)
607 std::ostringstream oss; oss << "GetTypesOfField : The field \"" << fieldName << "\" in file \"" << fileName << "\" is not lying on mesh \"" << meshName << "\"";
608 oss << " The name of the mesh in file is \"" << fs->getMeshName() << "\"!";
609 throw INTERP_KERNEL::Exception(oss.str().c_str());
611 int nbTS(fs->getNumberOfTS());
614 for(int i=0;i<nbTS;i++)
616 MCAuto<MEDFileAnyTypeField1TS> f1ts(fs->getTimeStepAtPos(i));
617 std::vector<MEDCoupling::TypeOfField> tof(f1ts->getTypesOfFieldAvailable());
618 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=tof.begin();it!=tof.end();it++)
619 if(std::find(ret.begin(),ret.end(),*it)==ret.end())
622 // sort ret to put before ON_NODES then ON_CELLS then the remaining.
623 std::vector<MEDCoupling::TypeOfField> ret2;
624 if(std::find(ret.begin(),ret.end(),ON_NODES)!=ret.end())
625 ret2.push_back(ON_NODES);
626 if(std::find(ret.begin(),ret.end(),ON_CELLS)!=ret.end())
627 ret2.push_back(ON_CELLS);
628 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=ret.begin();it!=ret.end();it++)
629 if(*it!=ON_NODES && *it!=ON_CELLS)
634 std::vector<std::string> MEDCoupling::GetAllFieldNames(const std::string& fileName)
636 std::vector<std::string> ret;
637 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
638 med_int nbFields=MEDnField(fid);
639 med_field_type typcha;
640 for(int i=0;i<nbFields;i++)
642 med_int ncomp(MEDfieldnComponent(fid,i+1));
643 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
644 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
645 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
646 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
647 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
650 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
651 ret.push_back(std::string(nomcha));
656 std::vector<std::string> MEDCoupling::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
658 std::vector<std::string> ret;
659 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
660 med_int nbFields=MEDnField(fid);
662 med_field_type typcha;
663 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
664 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
666 for(int i=0;i<nbFields;i++)
668 med_int ncomp(MEDfieldnComponent(fid,i+1));
669 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
670 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
671 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
674 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
675 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
676 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
678 if(curMeshName==meshName)
679 ret.push_back(curFieldName);
686 std::vector<std::string> MEDCoupling::GetFieldNamesOnMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName)
688 MEDCoupling::CheckFileForRead(fileName);
692 return GetCellFieldNamesOnMesh(fileName,meshName);
694 return GetNodeFieldNamesOnMesh(fileName,meshName);
696 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
700 std::vector<std::string> MEDCoupling::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
702 std::vector<std::string> ret;
703 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
704 med_int nbFields=MEDnField(fid);
706 med_field_type typcha;
707 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
708 med_int numdt=0,numo=0;
710 char pflname[MED_NAME_SIZE+1]="";
711 char locname[MED_NAME_SIZE+1]="";
712 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
713 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
714 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
718 for(int i=0;i<nbFields;i++)
720 med_int ncomp(MEDfieldnComponent(fid,i+1));
721 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
722 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
723 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
724 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
725 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
727 if(curMeshName==meshName)
730 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
734 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
735 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
736 pflname,&profilesize,locname,&nbi));
740 ret.push_back(curFieldName);
749 std::vector<std::string> MEDCoupling::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
751 std::vector<std::string> ret;
752 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
753 med_int nbFields=MEDnField(fid);
754 char pflname[MED_NAME_SIZE+1]="";
755 char locname[MED_NAME_SIZE+1]="";
757 med_field_type typcha;
758 med_int numdt=0,numo=0;
760 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
761 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
762 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
765 for(int i=0;i<nbFields;i++)
767 med_int ncomp(MEDfieldnComponent(fid,i+1));
768 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
769 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
771 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
772 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
773 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
777 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
778 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
779 pflname,&profilesize,locname,&nbi));
780 if(curMeshName==meshName && nbOfVal>0)
782 ret.push_back(curFieldName);
789 std::vector< std::pair< std::pair<int,int>, double> > MEDCoupling::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
791 std::vector< std::pair< std::pair<int,int>, double > > ret;
792 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
793 med_int nbFields=MEDnField(fid);
795 med_field_type typcha;
796 med_int numdt=0,numo=0;
798 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
799 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
800 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
803 std::ostringstream oss; oss << "GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
804 for(int i=0;i<nbFields;i++)
806 med_int ncomp(MEDfieldnComponent(fid,i+1));
807 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
808 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
810 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
811 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
812 if(curFieldName==fieldName)
814 for(int k=0;k<nbPdt;k++)
816 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
817 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
823 oss << "\"" << curFieldName << "\"";
824 if(i!=nbFields-1) oss << ", ";
828 throw INTERP_KERNEL::Exception(oss.str().c_str());
831 double MEDCoupling::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
833 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
834 med_int nbFields=MEDnField(fid);
836 med_field_type typcha;
837 med_int numdt=0,numo=0;
840 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
841 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
842 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
846 double ret=std::numeric_limits<double>::max();
847 for(int i=0;i<nbFields && !found;i++)
849 med_int ncomp(MEDfieldnComponent(fid,i+1));
850 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
851 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
853 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt));
854 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
855 if(curFieldName==fieldName)
858 for(int k=0;k<nbPdt;k++)
860 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
861 if(numdt==iteration && numo==order)
869 if(!found || !found2)
871 std::ostringstream oss;
872 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
873 throw INTERP_KERNEL::Exception(oss.str().c_str());
878 std::vector< std::pair<int,int> > MEDCoupling::GetFieldIterations(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
880 MEDCoupling::CheckFileForRead(fileName);
884 return GetCellFieldIterations(fileName,meshName,fieldName);
886 return GetNodeFieldIterations(fileName,meshName,fieldName);
888 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
892 std::vector< std::pair<int,int> > MEDCoupling::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
894 std::string meshNameCpp(meshName);
895 std::vector< std::pair<int,int> > ret;
896 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
897 med_int nbFields=MEDnField(fid);
899 med_field_type typcha;
900 med_int numdt=0,numo=0;
902 char pflname[MED_NAME_SIZE+1]="";
903 char locname[MED_NAME_SIZE+1]="";
904 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
905 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
906 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
909 std::ostringstream oss; oss << "GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
910 std::set<std::string> s2;
911 for(int i=0;i<nbFields;i++)
913 med_int ncomp(MEDfieldnComponent(fid,i+1));
914 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
915 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
917 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
918 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
919 if(curFieldName==fieldName)
922 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
924 for(int k=0;k<nbPdt;k++)
927 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
928 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
929 pflname,&profilesize,locname,&nbi));
930 std::string maa_ass_cpp(maa_ass);
933 if(meshNameCpp==maa_ass_cpp)
936 ret.push_back(std::make_pair(numdt,numo));
939 s2.insert(maa_ass_cpp);
946 oss << "\"" << curFieldName << "\"";
947 if(i!=nbFields-1) oss << ", ";
954 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
955 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
958 throw INTERP_KERNEL::Exception(oss.str().c_str());
963 std::vector< std::pair<int,int> > MEDCoupling::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
965 std::string meshNameCpp(meshName);
966 std::vector< std::pair<int,int> > ret;
967 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
968 med_int nbFields=MEDnField(fid);
970 med_field_type typcha;
971 med_int numdt=0,numo=0;
973 char pflname[MED_NAME_SIZE+1]="";
974 char locname[MED_NAME_SIZE+1]="";
975 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
976 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
977 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
980 std::ostringstream oss; oss << "GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
981 std::set<std::string> s2;
982 for(int i=0;i<nbFields;i++)
984 med_int ncomp(MEDfieldnComponent(fid,i+1));
985 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
986 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
988 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
989 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
990 if(curFieldName==fieldName)
992 for(int k=0;k<nbPdt;k++)
995 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
996 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
997 pflname,&profilesize,locname,&nbi));
998 std::string maa_ass_cpp(maa_ass);
1001 if(meshNameCpp==maa_ass_cpp)
1002 { ret.push_back(std::make_pair(numdt,numo)); }
1004 s2.insert(maa_ass_cpp);
1010 oss << "\"" << curFieldName << "\"";
1011 if(i!=nbFields-1) oss << ", ";
1018 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1019 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1022 throw INTERP_KERNEL::Exception(oss.str().c_str());
1027 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1029 MEDCoupling::CheckFileForRead(fileName);
1030 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1031 MEDFileMesh *mmPtr(mm);
1032 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1034 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1035 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1038 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1039 return const_cast<MEDCouplingCMesh *>(ret);
1041 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1044 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1045 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1047 std::ostringstream oss; oss << "ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1048 throw INTERP_KERNEL::Exception(oss.str().c_str());
1051 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1053 MEDCoupling::CheckFileForRead(fileName);
1054 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1055 MEDFileMesh *mmPtr(mm);
1056 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1058 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1059 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1062 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1063 return const_cast<MEDCouplingCMesh *>(ret);
1065 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1068 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1069 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1071 std::ostringstream oss; oss << "ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1072 throw INTERP_KERNEL::Exception(oss.str().c_str());
1075 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1077 MEDCoupling::CheckFileForRead(fileName);
1078 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1079 MEDFileMesh *mmPtr(mm);
1080 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1083 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1084 throw INTERP_KERNEL::Exception(oss.str().c_str());
1086 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1089 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1091 MEDCoupling::CheckFileForRead(fileName);
1092 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1093 MEDFileMesh *mmPtr(mm);
1094 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1097 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1098 throw INTERP_KERNEL::Exception(oss.str().c_str());
1100 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1103 int MEDCoupling::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1105 MEDCoupling::CheckFileForRead(fileName);
1106 std::vector<int> poss;
1107 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1110 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1112 MEDCoupling::CheckFileForRead(fileName);
1113 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1114 MEDFileMesh *mmPtr(mm);
1115 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1118 std::ostringstream oss; oss << "ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1119 throw INTERP_KERNEL::Exception(oss.str().c_str());
1121 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1124 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1126 MEDCoupling::CheckFileForRead(fileName);
1127 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1128 MEDFileMesh *mmPtr(mm);
1129 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1132 std::ostringstream oss; oss << "ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1133 throw INTERP_KERNEL::Exception(oss.str().c_str());
1135 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1138 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)
1140 MEDCoupling::CheckFileForRead(fileName);
1144 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1146 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1148 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1150 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1152 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1156 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsOnSameMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1157 const std::vector<std::pair<int,int> >& its)
1160 return std::vector<MEDCoupling::MEDCouplingFieldDouble *>();
1161 MEDCoupling::CheckFileForRead(fileName);
1162 std::vector<MEDCoupling::MEDCouplingFieldDouble *> ret(its.size());
1163 std::vector< MCAuto<MEDCouplingFieldDouble> > retSafe(its.size());
1166 //Retrieving mesh of rank 0 and field on rank 0 too.
1167 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1168 MEDFileMesh *mmPtr(mm);
1169 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1171 throw INTERP_KERNEL::Exception("ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1172 MCAuto<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1173 const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1174 MCAuto<MEDCouplingUMesh> m2(m->clone(true));
1176 m2->renumberCells(o2n->begin(),true);
1178 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1180 MCAuto<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1181 MCAuto<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1183 retElt->renumberCells(o2n->begin(),true);
1184 retElt->setMesh(m2);
1188 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1189 ret[i]=retSafe[i].retn();
1193 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1194 const std::vector<std::pair<int,int> >& its)
1196 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1199 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1200 const std::vector<std::pair<int,int> >& its)
1202 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1205 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1206 const std::vector<std::pair<int,int> >& its)
1208 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1211 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1212 const std::vector<std::pair<int,int> >& its)
1214 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1217 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1219 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1220 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1221 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1222 MEDFileMesh *mPtr(mm);
1223 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1224 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_CELLS,m));
1227 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1229 ret->renumberCells(num->begin());
1234 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1236 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1237 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1238 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1239 MEDFileMesh *mPtr(mm);
1240 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_NODES,m));
1241 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1242 if(ff->getPflsReallyUsed().empty())
1246 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1248 ret->renumberCells(num->begin());
1253 DataArrayInt *pfl=0,*arr2=0;
1254 MCAuto<DataArrayDouble> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl));
1255 MCAuto<DataArrayInt> pflSafe(pfl);
1256 MCAuto<DataArrayInt> mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end()));
1257 MCAuto<MEDCouplingUMesh> mzip(static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2)));
1258 MCAuto<DataArrayInt> arr2Safe(arr2);
1259 MCAuto<DataArrayInt> arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes()));
1260 MCAuto<DataArrayInt> pflSorted(pflSafe->deepCopy()); pflSorted->sort(true);
1261 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1262 throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !");
1263 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1265 MCAuto<DataArrayInt> o2n2(pflSafe->checkAndPreparePermutation());
1266 MCAuto<DataArrayInt> n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples()));
1267 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1276 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1278 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1279 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1280 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1281 MEDFileMesh *mPtr(mm);
1282 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1283 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m));
1286 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1288 ret->renumberCells(num->begin());
1293 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1295 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1296 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1297 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1298 MEDFileMesh *mPtr(mm);
1299 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1300 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m));
1303 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1305 ret->renumberCells(num->begin());
1310 void MEDCoupling::WriteMesh(const std::string& fileName, const MEDCoupling::MEDCouplingMesh *mesh, bool writeFromScratch)
1313 throw INTERP_KERNEL::Exception("WriteMesh : input mesh is null !");
1314 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1317 WriteUMesh(fileName,um,writeFromScratch);
1320 int mod=writeFromScratch?2:0;
1321 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1324 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1325 AssignStaticWritePropertiesTo(*mmu);
1326 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1327 mmu->write(fileName,mod);
1330 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1333 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1334 AssignStaticWritePropertiesTo(*mmc);
1335 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1336 mmc->write(fileName,mod);
1339 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1342 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1343 AssignStaticWritePropertiesTo(*mmc);
1344 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1345 mmc->write(fileName,mod);
1348 throw INTERP_KERNEL::Exception("WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1351 void MEDCoupling::WriteUMesh(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1354 throw INTERP_KERNEL::Exception("WriteUMesh : input mesh is null !");
1355 int mod=writeFromScratch?2:0;
1356 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1357 AssignStaticWritePropertiesTo(*m);
1358 MCAuto<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCopy()));
1359 m->setMeshAtLevel(0,mcpy,true);
1360 m->write(fileName,mod);
1363 void MEDCoupling::WriteUMeshDep(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1365 WriteUMesh(fileName,mesh,writeFromScratch);
1368 void MEDCoupling::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1370 std::string meshName(meshNameC);
1371 if(meshName.empty())
1372 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 !");
1373 int status=MEDLoaderBase::getStatusOfFile(fileName);
1374 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1376 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1377 throw INTERP_KERNEL::Exception(oss.str().c_str());
1379 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1380 AssignStaticWritePropertiesTo(*m);
1381 m->setGroupsFromScratch(0,meshes,true);
1382 m->setName(meshNameC);
1383 int mod=writeFromScratch?2:0;
1384 m->write(fileName,mod);
1387 void MEDCoupling::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1389 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1392 void MEDCoupling::WriteUMeshes(const std::string& fileName, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1394 int mod=writeFromScratch?2:0;
1395 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1396 AssignStaticWritePropertiesTo(*m);
1397 m->setMeshes(meshes,true);
1398 m->write(fileName,mod);
1401 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1403 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New());
1404 AssignStaticWritePropertiesTo(*ff);
1405 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1406 const MEDCouplingMesh *m(f2->getMesh());
1407 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1408 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1409 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1410 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1411 MCAuto<MEDFileMesh> mm;
1412 int mod=writeFromScratch?2:0;
1415 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1416 AssignStaticWritePropertiesTo(*mmu);
1417 MCAuto<DataArrayInt> o2n(um->getRenumArrForMEDFileFrmt());
1418 MCAuto<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1419 f2->renumberCells(o2n->begin(),false);
1420 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1421 mmu->setRenumFieldArr(0,n2o);
1422 ff->setFieldNoProfileSBT(f2);
1423 mmu->write(fileName,mod);
1427 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1428 AssignStaticWritePropertiesTo(*mmu);
1429 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1430 ff->setFieldNoProfileSBT(f2);
1431 mmu->write(fileName,mod);
1435 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1436 AssignStaticWritePropertiesTo(*mmc);
1437 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1438 ff->setFieldNoProfileSBT(f2);
1439 mmc->write(fileName,mod);
1443 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1444 AssignStaticWritePropertiesTo(*mmc);
1445 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1446 ff->setFieldNoProfileSBT(f2);
1447 mmc->write(fileName,mod);
1450 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1451 ff->write(fileName,0);
1454 void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1457 throw INTERP_KERNEL::Exception("WriteField : input field is NULL !");
1458 f->checkConsistencyLight();
1459 int status=MEDLoaderBase::getStatusOfFile(fileName);
1460 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1462 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1463 throw INTERP_KERNEL::Exception(oss.str().c_str());
1465 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1467 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
1471 std::vector<std::string> meshNames=GetMeshNames(fileName);
1473 throw INTERP_KERNEL::Exception("WriteField : trying to write a field with no mesh !");
1474 std::string fileNameCpp(f->getMesh()->getName());
1475 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1476 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
1479 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1480 AssignStaticWritePropertiesTo(*mm);
1481 const MEDFileMesh *mmPtr(mm);
1482 const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
1484 throw INTERP_KERNEL::Exception("WriteField : only umeshes are supported now !");
1485 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1486 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1488 throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !");
1489 MCAuto<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1490 f2->renumberCells(o2n->begin(),false);
1491 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1492 MCAuto<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
1493 if(f2->getTypeOfField()!=ON_NODES)
1495 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1496 DataArrayInt *part=0;
1497 bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
1498 MCAuto<DataArrayInt> partSafe(part);
1501 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 !";
1502 throw INTERP_KERNEL::Exception(oss.str().c_str());
1504 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1505 AssignStaticWritePropertiesTo(*f1ts);
1506 if(part->isIota(mread->getNumberOfCells()))
1507 f1ts->setFieldNoProfileSBT(f2);
1510 part->setName(f1ts->createNewNameOfPfl().c_str());
1511 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1513 f1ts->write(fileName,0);
1518 DataArrayInt *part=0;
1519 bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
1520 MCAuto<DataArrayInt> partSafe(part);
1523 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 !";
1524 throw INTERP_KERNEL::Exception(oss.str().c_str());
1526 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1527 AssignStaticWritePropertiesTo(*f1ts);
1528 if(part->isIota(mread->getNumberOfNodes()))
1529 f1ts->setFieldNoProfileSBT(f2);
1532 part->setName(f1ts->createNewNameOfPfl().c_str());
1533 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1535 f1ts->write(fileName,0);
1541 void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1543 WriteField(fileName,f,writeFromScratch);
1546 void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f)
1549 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1550 f->checkConsistencyLight();
1551 int status=MEDLoaderBase::getStatusOfFile(fileName);
1552 if(status!=MEDLoaderBase::EXIST_RW)
1554 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1555 throw INTERP_KERNEL::Exception(oss.str().c_str());
1557 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1558 AssignStaticWritePropertiesTo(*f1ts);
1559 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1562 MCAuto<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
1563 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1564 f2->renumberCells(o2n->begin(),false);
1565 f1ts->setFieldNoProfileSBT(f2);
1568 f1ts->setFieldNoProfileSBT(f);
1569 f1ts->write(fileName,0);