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,
74 med_geometry_type typmainoeud[1] = { MED_NONE };
76 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
77 INTERP_KERNEL::NORM_SEG2,
78 INTERP_KERNEL::NORM_SEG3,
79 INTERP_KERNEL::NORM_SEG4,
80 INTERP_KERNEL::NORM_TRI3,
81 INTERP_KERNEL::NORM_QUAD4,
82 INTERP_KERNEL::NORM_TRI6,
83 INTERP_KERNEL::NORM_TRI7,
84 INTERP_KERNEL::NORM_QUAD8,
85 INTERP_KERNEL::NORM_QUAD9,
86 INTERP_KERNEL::NORM_TETRA4,
87 INTERP_KERNEL::NORM_PYRA5,
88 INTERP_KERNEL::NORM_PENTA6,
89 INTERP_KERNEL::NORM_HEXA8,
90 INTERP_KERNEL::NORM_HEXGP12,
91 INTERP_KERNEL::NORM_TETRA10,
92 INTERP_KERNEL::NORM_PYRA13,
93 INTERP_KERNEL::NORM_PENTA15,
94 INTERP_KERNEL::NORM_PENTA18,
95 INTERP_KERNEL::NORM_HEXA20,
96 INTERP_KERNEL::NORM_HEXA27,
97 INTERP_KERNEL::NORM_POLYGON,
98 INTERP_KERNEL::NORM_QPOLYG,
99 INTERP_KERNEL::NORM_POLYHED };
101 med_geometry_type typmai3[34] = { MED_POINT1,//0
137 double _EPS_FOR_NODE_COMP=1.e-12;
139 int _COMP_FOR_CELL=0;
143 using namespace MEDCoupling;
148 * This method returns a first quick overview of mesh with name \a meshName into the file \a fileName.
149 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
150 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
152 int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities)
154 possibilities.clear();
155 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
158 char nommaa[MED_NAME_SIZE+1];
159 char maillage_description[MED_COMMENT_SIZE+1];
160 med_mesh_type type_maillage;
162 std::string trueMeshName;
163 med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
164 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
165 med_sorting_type sortingType;
167 med_axis_type axisType;
168 int naxis(MEDmeshnAxis(fid,meshId));
169 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
170 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
171 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
175 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
179 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
181 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
183 med_geometry_type curMedType=typmai[i];
184 med_bool changement,transformation;
185 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
186 int curNbOfElemF(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));//limitation
188 med_entity_type whichEntity;
189 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
192 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
193 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
200 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
201 possibilities.push_back(*it-ret);
208 med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName)
212 std::vector<std::string> meshes=getMeshNamesFid(fid);
214 throw INTERP_KERNEL::Exception("No mesh in file");
215 trueMeshName=meshes[0];
218 std::string meshNameStr(meshName);
219 std::vector<std::string> meshes=getMeshNamesFid(fid);
221 throw INTERP_KERNEL::Exception("No mesh in file");
222 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
223 if(iter==meshes.end())
225 std::ostringstream os2;
226 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
227 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
228 throw INTERP_KERNEL::Exception(os2.str().c_str());
230 trueMeshName=meshName;
231 return iter-meshes.begin()+1;
234 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
236 med_mesh_type type_maillage;
237 char maillage_description[MED_COMMENT_SIZE+1];
238 char dtunit[MED_COMMENT_SIZE+1];
241 char nommaa[MED_NAME_SIZE+1];
242 med_axis_type axistype;
243 med_sorting_type stype;
244 med_int n=MEDnMesh(fid);
245 std::vector<std::string> ret(n);
248 int naxis(MEDmeshnAxis(fid,i+1));
249 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
250 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
252 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
253 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
260 * This methods allows to merger all entities and to considerate only cell types.
262 void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
264 if(nbOfElemCell>=nbOfElemFace)
266 whichEntity=MED_CELL;
267 nbOfElem=nbOfElemCell;
271 whichEntity=MED_CELL;
272 nbOfElem=nbOfElemFace;
278 void MEDCoupling::AssignStaticWritePropertiesTo(MEDCoupling::MEDFileWritable& obj)
280 obj.setTooLongStrPolicy(_TOO_LONG_STR);
283 bool MEDCoupling::HasXDR()
292 std::string MEDCoupling::MEDFileVersionStr()
296 std::fill(buf,buf+SZ,'\0');
297 const char START_EXPECTED[]="MED-";
298 med_err ret(MEDlibraryStrVersion(buf));
300 throw INTERP_KERNEL::Exception("MEDFileVersionStr : fail to find version of MED file ! It looks very bad !");
301 std::string zeRet(buf);
302 std::size_t pos(zeRet.find(START_EXPECTED,0));
305 std::ostringstream oss; oss << "MEDFileVersionStr : internal error ! The MEDFile returned version (\"" << zeRet << "\") has not the right pattern !";
306 throw INTERP_KERNEL::Exception(oss.str());
308 return zeRet.substr(sizeof(START_EXPECTED)-1,std::string::npos);
311 std::string MEDCoupling::MEDFileVersionOfFileStr(const std::string& fileName)
313 #if MED_NUM_MAJEUR>3 || ( MED_NUM_MAJEUR==3 && ( (MED_NUM_MINEUR==2 && MED_NUM_RELEASE>=1) || MED_NUM_MINEUR>=3) )
314 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
316 const char START_EXPECTED[]="MED-";
318 std::fill(buf,buf+SZ,'\0');
319 MEDFILESAFECALLERRD0(MEDfileStrVersionRd,(fid,buf));
320 std::string ret(buf);
321 std::size_t pos(ret.find(START_EXPECTED,0));
324 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : internal error ! The MEDFile returned version (\"" << ret << "\") has not the right pattern !";
325 throw INTERP_KERNEL::Exception(oss.str());
327 return ret.substr(sizeof(START_EXPECTED)-1,std::string::npos);
329 std::ostringstream oss; oss << "MEDFileVersionOfFileStr : is implemented with MEDFile " << MEDFileVersionStr() << " ! If you need this feature please use version >= 3.2.1.";
330 throw INTERP_KERNEL::Exception(oss.str());
334 void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
336 med_int majj,minn,rell;
337 med_err ret(MEDlibraryNumVersion(&majj,&minn,&rell));
339 throw INTERP_KERNEL::Exception("MEDFileVersion : fail to call MEDlibraryNumVersion ! It looks very bad !");
346 * 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.
348 void MEDCoupling::SetEpsilonForNodeComp(double val)
350 _EPS_FOR_NODE_COMP=val;
354 * 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.
356 void MEDCoupling::SetCompPolicyForCell(int val)
362 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
363 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
365 void MEDCoupling::SetTooLongStrPolicy(int val)
371 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
372 * It returns, in this order :
373 * - 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...
374 * - the mesh dimension
375 * - the space dimension
376 * - the number of nodes
378 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)
380 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
382 char nommaa[MED_NAME_SIZE+1];
383 char maillage_description[MED_COMMENT_SIZE+1];
384 med_mesh_type type_maillage;
385 std::string trueMeshName;
386 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
387 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
388 med_sorting_type sortingType;
390 med_axis_type axisType;
391 int naxis(MEDmeshnAxis(fid,meshId));
392 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
393 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
394 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
395 if(type_maillage!=MED_UNSTRUCTURED_MESH)
397 std::ostringstream oss; oss << "GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
398 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
399 throw INTERP_KERNEL::Exception(oss.str().c_str());
403 throw INTERP_KERNEL::Exception("GetUMeshGlobalInfo : multisteps on mesh not managed !");
406 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
408 std::vector<int> dims;
409 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
410 med_bool changement,transformation;
411 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
413 med_geometry_type curMedType=typmai[i];
414 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
417 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
418 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
419 dims.push_back(mdimCell);
420 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
423 int maxLev=*std::max_element(dims.begin(),dims.end());
424 int lowLev=*std::min_element(dims.begin(),dims.end());
425 int nbOfLevels=maxLev-lowLev+1;
426 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
427 for(std::size_t i=0;i<dims.size();i++)
429 ret[maxLev-dims[i]].push_back(geoTypes[i]);
431 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
435 void MEDCoupling::CheckFileForRead(const std::string& fileName)
437 MEDFileUtilities::CheckFileForRead(fileName);
440 std::vector<std::string> MEDCoupling::GetMeshNames(const std::string& fileName)
442 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
443 return MEDLoaderNS::getMeshNamesFid(fid);
446 std::vector< std::pair<std::string,std::string> > MEDCoupling::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
448 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
449 med_int nbFields(MEDnField(fid));
450 std::vector<std::string> fields(nbFields);
451 med_field_type typcha;
452 for(int i=0;i<nbFields;i++)
454 med_int ncomp(MEDfieldnComponent(fid,i+1));
455 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
456 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
457 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
460 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
461 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
462 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
463 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
464 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
465 if(curFieldName==fieldName)
467 std::vector< std::pair<std::string,std::string> > ret(ncomp);
468 for(int j=0;j<ncomp;j++)
469 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
470 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
473 fields[i]=curFieldName;
475 std::ostringstream oss; oss << "GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
476 oss << "Possible field names are : " << std::endl;
477 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
478 throw INTERP_KERNEL::Exception(oss.str().c_str());
481 std::vector<std::string> MEDCoupling::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
483 std::vector<std::string> ret;
485 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
486 med_int nbFields=MEDnField(fid);
488 med_field_type typcha;
489 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
490 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
493 for(int i=0;i<nbFields;i++)
495 med_int ncomp(MEDfieldnComponent(fid,i+1));
496 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
497 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
499 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
500 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
501 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
502 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
503 if(curFieldName==fieldName)
504 ret.push_back(meshName);
509 std::vector<std::string> MEDCoupling::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
511 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
512 med_int nfam=MEDnFamily(fid,meshName.c_str());
513 std::vector<std::string> ret(nfam);
514 char nomfam[MED_NAME_SIZE+1];
516 for(int i=0;i<nfam;i++)
518 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
519 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
520 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
521 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
522 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
523 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
524 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
525 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
532 std::vector<std::string> MEDCoupling::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
534 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
535 med_int nfam=MEDnFamily(fid,meshName.c_str());
536 std::vector<std::string> ret;
537 char nomfam[MED_NAME_SIZE+1];
539 for(int i=0;i<nfam;i++)
541 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
542 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
543 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
544 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
545 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
546 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
547 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
548 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
549 for(int j=0;j<ngro;j++)
551 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
559 std::vector<std::string> MEDCoupling::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
561 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
562 med_int nfam(MEDnFamily(fid,meshName.c_str()));
563 std::vector<std::string> ret;
564 char nomfam[MED_NAME_SIZE+1];
567 for(int i=0;i<nfam && !found;i++)
569 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
570 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
571 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
572 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
573 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
574 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
575 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
576 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
577 found=(cur==famName);
579 for(int j=0;j<ngro;j++)
581 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
587 std::ostringstream oss;
588 oss << "GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
589 throw INTERP_KERNEL::Exception(oss.str().c_str());
595 std::vector<std::string> MEDCoupling::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
597 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
598 med_int nfam=MEDnFamily(fid,meshName.c_str());
599 std::vector<std::string> ret;
600 char nomfam[MED_NAME_SIZE+1];
602 for(int i=0;i<nfam;i++)
604 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
605 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
606 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
607 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
608 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
609 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
610 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
611 for(int j=0;j<ngro;j++)
613 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
614 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
621 std::vector<MEDCoupling::TypeOfField> MEDCoupling::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
623 std::vector<MEDCoupling::TypeOfField> ret;
624 MCAuto<MEDFileAnyTypeFieldMultiTS> fs(MEDFileAnyTypeFieldMultiTS::New(fileName,fieldName,false));
625 if(fs->getMeshName()!=meshName)
627 std::ostringstream oss; oss << "GetTypesOfField : The field \"" << fieldName << "\" in file \"" << fileName << "\" is not lying on mesh \"" << meshName << "\"";
628 oss << " The name of the mesh in file is \"" << fs->getMeshName() << "\"!";
629 throw INTERP_KERNEL::Exception(oss.str().c_str());
631 int nbTS(fs->getNumberOfTS());
634 for(int i=0;i<nbTS;i++)
636 MCAuto<MEDFileAnyTypeField1TS> f1ts(fs->getTimeStepAtPos(i));
637 std::vector<MEDCoupling::TypeOfField> tof(f1ts->getTypesOfFieldAvailable());
638 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=tof.begin();it!=tof.end();it++)
639 if(std::find(ret.begin(),ret.end(),*it)==ret.end())
642 // sort ret to put before ON_NODES then ON_CELLS then the remaining.
643 std::vector<MEDCoupling::TypeOfField> ret2;
644 if(std::find(ret.begin(),ret.end(),ON_NODES)!=ret.end())
645 ret2.push_back(ON_NODES);
646 if(std::find(ret.begin(),ret.end(),ON_CELLS)!=ret.end())
647 ret2.push_back(ON_CELLS);
648 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=ret.begin();it!=ret.end();it++)
649 if(*it!=ON_NODES && *it!=ON_CELLS)
654 std::vector<std::string> MEDCoupling::GetAllFieldNames(const std::string& fileName)
656 std::vector<std::string> ret;
657 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
658 med_int nbFields=MEDnField(fid);
659 med_field_type typcha;
660 for(int i=0;i<nbFields;i++)
662 med_int ncomp(MEDfieldnComponent(fid,i+1));
663 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
664 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
665 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
666 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
667 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
670 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
671 ret.push_back(std::string(nomcha));
676 std::vector<std::string> MEDCoupling::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
678 std::vector<std::string> ret;
679 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
680 med_int nbFields=MEDnField(fid);
682 med_field_type typcha;
683 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
684 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
686 for(int i=0;i<nbFields;i++)
688 med_int ncomp(MEDfieldnComponent(fid,i+1));
689 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
690 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
691 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
694 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
695 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
696 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
698 if(curMeshName==meshName)
699 ret.push_back(curFieldName);
706 std::vector<std::string> MEDCoupling::GetFieldNamesOnMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName)
708 MEDCoupling::CheckFileForRead(fileName);
712 return GetCellFieldNamesOnMesh(fileName,meshName);
714 return GetNodeFieldNamesOnMesh(fileName,meshName);
716 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
720 std::vector<std::string> MEDCoupling::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
722 std::vector<std::string> ret;
723 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
724 med_int nbFields=MEDnField(fid);
726 med_field_type typcha;
727 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
728 med_int numdt=0,numo=0;
730 char pflname[MED_NAME_SIZE+1]="";
731 char locname[MED_NAME_SIZE+1]="";
732 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
733 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
734 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
738 for(int i=0;i<nbFields;i++)
740 med_int ncomp(MEDfieldnComponent(fid,i+1));
741 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
742 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
743 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
744 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
745 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
747 if(curMeshName==meshName)
750 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
754 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
755 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
756 pflname,&profilesize,locname,&nbi));
760 ret.push_back(curFieldName);
769 std::vector<std::string> MEDCoupling::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
771 std::vector<std::string> ret;
772 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
773 med_int nbFields=MEDnField(fid);
774 char pflname[MED_NAME_SIZE+1]="";
775 char locname[MED_NAME_SIZE+1]="";
777 med_field_type typcha;
778 med_int numdt=0,numo=0;
780 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
781 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
782 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
785 for(int i=0;i<nbFields;i++)
787 med_int ncomp(MEDfieldnComponent(fid,i+1));
788 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
789 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
791 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
792 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
793 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
797 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
798 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
799 pflname,&profilesize,locname,&nbi));
800 if(curMeshName==meshName && nbOfVal>0)
802 ret.push_back(curFieldName);
809 std::vector< std::pair< std::pair<int,int>, double> > MEDCoupling::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
811 std::vector< std::pair< std::pair<int,int>, double > > ret;
812 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
813 med_int nbFields=MEDnField(fid);
815 med_field_type typcha;
816 med_int numdt=0,numo=0;
818 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
819 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
820 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
823 std::ostringstream oss; oss << "GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
824 for(int i=0;i<nbFields;i++)
826 med_int ncomp(MEDfieldnComponent(fid,i+1));
827 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
828 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
830 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
831 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
832 if(curFieldName==fieldName)
834 for(int k=0;k<nbPdt;k++)
836 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
837 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
843 oss << "\"" << curFieldName << "\"";
844 if(i!=nbFields-1) oss << ", ";
848 throw INTERP_KERNEL::Exception(oss.str().c_str());
851 double MEDCoupling::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
853 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
854 med_int nbFields=MEDnField(fid);
856 med_field_type typcha;
857 med_int numdt=0,numo=0;
860 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
861 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
862 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
866 double ret=std::numeric_limits<double>::max();
867 for(int i=0;i<nbFields && !found;i++)
869 med_int ncomp(MEDfieldnComponent(fid,i+1));
870 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
871 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
873 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt));
874 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
875 if(curFieldName==fieldName)
878 for(int k=0;k<nbPdt;k++)
880 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
881 if(numdt==iteration && numo==order)
889 if(!found || !found2)
891 std::ostringstream oss;
892 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
893 throw INTERP_KERNEL::Exception(oss.str().c_str());
898 std::vector< std::pair<int,int> > MEDCoupling::GetFieldIterations(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
900 MEDCoupling::CheckFileForRead(fileName);
904 return GetCellFieldIterations(fileName,meshName,fieldName);
906 return GetNodeFieldIterations(fileName,meshName,fieldName);
908 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
912 std::vector< std::pair<int,int> > MEDCoupling::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
914 std::string meshNameCpp(meshName);
915 std::vector< std::pair<int,int> > ret;
916 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
917 med_int nbFields=MEDnField(fid);
919 med_field_type typcha;
920 med_int numdt=0,numo=0;
922 char pflname[MED_NAME_SIZE+1]="";
923 char locname[MED_NAME_SIZE+1]="";
924 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
925 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
926 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
929 std::ostringstream oss; oss << "GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
930 std::set<std::string> s2;
931 for(int i=0;i<nbFields;i++)
933 med_int ncomp(MEDfieldnComponent(fid,i+1));
934 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
935 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
937 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
938 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
939 if(curFieldName==fieldName)
942 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
944 for(int k=0;k<nbPdt;k++)
947 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
948 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
949 pflname,&profilesize,locname,&nbi));
950 std::string maa_ass_cpp(maa_ass);
953 if(meshNameCpp==maa_ass_cpp)
956 ret.push_back(std::make_pair(numdt,numo));
959 s2.insert(maa_ass_cpp);
966 oss << "\"" << curFieldName << "\"";
967 if(i!=nbFields-1) oss << ", ";
974 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
975 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
978 throw INTERP_KERNEL::Exception(oss.str().c_str());
983 std::vector< std::pair<int,int> > MEDCoupling::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
985 std::string meshNameCpp(meshName);
986 std::vector< std::pair<int,int> > ret;
987 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
988 med_int nbFields=MEDnField(fid);
990 med_field_type typcha;
991 med_int numdt=0,numo=0;
993 char pflname[MED_NAME_SIZE+1]="";
994 char locname[MED_NAME_SIZE+1]="";
995 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
996 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
997 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1000 std::ostringstream oss; oss << "GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
1001 std::set<std::string> s2;
1002 for(int i=0;i<nbFields;i++)
1004 med_int ncomp(MEDfieldnComponent(fid,i+1));
1005 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
1006 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1008 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
1009 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1010 if(curFieldName==fieldName)
1012 for(int k=0;k<nbPdt;k++)
1014 int profilesize,nbi;
1015 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
1016 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1017 pflname,&profilesize,locname,&nbi));
1018 std::string maa_ass_cpp(maa_ass);
1021 if(meshNameCpp==maa_ass_cpp)
1022 { ret.push_back(std::make_pair(numdt,numo)); }
1024 s2.insert(maa_ass_cpp);
1030 oss << "\"" << curFieldName << "\"";
1031 if(i!=nbFields-1) oss << ", ";
1038 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1039 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1042 throw INTERP_KERNEL::Exception(oss.str().c_str());
1047 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1049 MEDCoupling::CheckFileForRead(fileName);
1050 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1051 MEDFileMesh *mmPtr(mm);
1052 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1054 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1055 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1058 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1059 return const_cast<MEDCouplingCMesh *>(ret);
1061 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1064 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1065 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1067 std::ostringstream oss; oss << "ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1068 throw INTERP_KERNEL::Exception(oss.str().c_str());
1071 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1073 MEDCoupling::CheckFileForRead(fileName);
1074 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1075 MEDFileMesh *mmPtr(mm);
1076 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1078 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1079 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1082 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1083 return const_cast<MEDCouplingCMesh *>(ret);
1085 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1088 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1089 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1091 std::ostringstream oss; oss << "ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1092 throw INTERP_KERNEL::Exception(oss.str().c_str());
1095 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1097 MEDCoupling::CheckFileForRead(fileName);
1098 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1099 MEDFileMesh *mmPtr(mm);
1100 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1103 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1104 throw INTERP_KERNEL::Exception(oss.str().c_str());
1106 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1109 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1111 MEDCoupling::CheckFileForRead(fileName);
1112 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1113 MEDFileMesh *mmPtr(mm);
1114 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1117 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1118 throw INTERP_KERNEL::Exception(oss.str().c_str());
1120 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1123 int MEDCoupling::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1125 MEDCoupling::CheckFileForRead(fileName);
1126 std::vector<int> poss;
1127 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1130 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1132 MEDCoupling::CheckFileForRead(fileName);
1133 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1134 MEDFileMesh *mmPtr(mm);
1135 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1138 std::ostringstream oss; oss << "ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1139 throw INTERP_KERNEL::Exception(oss.str().c_str());
1141 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1144 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1146 MEDCoupling::CheckFileForRead(fileName);
1147 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1148 MEDFileMesh *mmPtr(mm);
1149 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1152 std::ostringstream oss; oss << "ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1153 throw INTERP_KERNEL::Exception(oss.str().c_str());
1155 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1158 MCAuto<MEDCoupling::MEDCouplingFieldDouble> MEDCoupling::ReadField(const std::string& fileName)
1160 std::vector<std::string> fieldNames(GetAllFieldNames(fileName));
1161 std::size_t sz(fieldNames.size());
1164 std::ostringstream oss;
1165 oss << "The file \"" << fileName << "\" contains no field !";
1166 throw INTERP_KERNEL::Exception(oss.str());
1170 std::ostringstream oss;
1171 oss << "In file \"" << fileName << "\" there are more than one field !" << std::endl;
1172 oss << "You are invited to use ReadField(fileName, fieldName) instead to avoid misleading concerning field you want to read !" << std::endl;
1173 oss << "For information, fields available are :" << std::endl;
1174 for(std::vector<std::string>::const_iterator it=fieldNames.begin();it!=fieldNames.end();it++)
1175 oss << " - \"" << *it << "\"" << std::endl;
1176 throw INTERP_KERNEL::Exception(oss.str());
1178 return ReadField(fileName,fieldNames[0]);
1181 MCAuto<MEDCoupling::MEDCouplingFieldDouble> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName)
1183 std::vector< std::pair< std::pair<int,int>, double> > iterations(GetAllFieldIterations(fileName,fieldName));
1184 std::size_t sz(iterations.size());
1187 std::ostringstream oss;
1188 oss << "In file \"" << fileName << "\" field \"" << fieldName << "\" exists but with no time steps !";
1189 throw INTERP_KERNEL::Exception(oss.str());
1193 std::ostringstream oss;
1194 oss << "In file \"" << fileName << "\" field \"" << fieldName << "\" exists but with more than one time steps !" << std::endl;
1195 oss << "You are invited to use ReadField(fileName, fieldName, iteration, order) instead to avoid misleading concerning time steps." << std::endl;
1196 oss << "For information, time steps available for field \"" << fieldName << "\" are :" << std::endl;
1197 for(std::vector< std::pair< std::pair<int,int>, double> >::const_iterator it=iterations.begin();it!=iterations.end();it++)
1198 oss << " - " << (*it).first.first << ", " << (*it).first.second << " (" << (*it).second << ")" << std::endl;
1199 throw INTERP_KERNEL::Exception(oss.str());
1201 return ReadField(fileName,fieldName,iterations[0].first.first,iterations[0].first.second);
1204 MCAuto<MEDCoupling::MEDCouplingFieldDouble> MEDCoupling::ReadField(const std::string& fileName, const std::string& fieldName, int iteration, int order)
1206 MCAuto<MEDFileField1TS> f(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1207 MCAuto<MEDFileMesh> mesh(MEDFileMesh::New(fileName,f->getMeshName()));
1208 MCAuto<MEDCoupling::MEDCouplingFieldDouble> ret(f->field(mesh));
1212 MCAuto<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)
1214 MEDCoupling::CheckFileForRead(fileName);
1218 return MCAuto<MEDCoupling::MEDCouplingFieldDouble>(ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1220 return MCAuto<MEDCoupling::MEDCouplingFieldDouble>(ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1222 return MCAuto<MEDCoupling::MEDCouplingFieldDouble>(ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1224 return MCAuto<MEDCoupling::MEDCouplingFieldDouble>(ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order));
1226 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1230 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsOnSameMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1231 const std::vector<std::pair<int,int> >& its)
1234 return std::vector<MEDCoupling::MEDCouplingFieldDouble *>();
1235 MEDCoupling::CheckFileForRead(fileName);
1236 std::vector<MEDCoupling::MEDCouplingFieldDouble *> ret(its.size());
1237 std::vector< MCAuto<MEDCouplingFieldDouble> > retSafe(its.size());
1240 //Retrieving mesh of rank 0 and field on rank 0 too.
1241 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1242 MEDFileMesh *mmPtr(mm);
1243 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1245 throw INTERP_KERNEL::Exception("ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1246 MCAuto<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1247 const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1248 MCAuto<MEDCouplingUMesh> m2(m->clone(true));
1250 m2->renumberCells(o2n->begin(),true);
1252 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1254 MCAuto<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1255 MCAuto<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1257 retElt->renumberCells(o2n->begin(),true);
1258 retElt->setMesh(m2);
1262 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1263 ret[i]=retSafe[i].retn();
1267 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1268 const std::vector<std::pair<int,int> >& its)
1270 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1273 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1274 const std::vector<std::pair<int,int> >& its)
1276 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1279 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1280 const std::vector<std::pair<int,int> >& its)
1282 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1285 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1286 const std::vector<std::pair<int,int> >& its)
1288 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1291 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1293 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1294 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1295 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1296 MEDFileMesh *mPtr(mm);
1297 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1298 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_CELLS,m));
1301 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1303 ret->renumberCells(num->begin());
1308 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1310 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1311 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1312 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1313 MEDFileMesh *mPtr(mm);
1314 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_NODES,m));
1315 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1316 if(ff->getPflsReallyUsed().empty())
1320 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1322 ret->renumberCells(num->begin());
1327 DataArrayInt *pfl=0,*arr2=0;
1328 MCAuto<DataArrayDouble> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl));
1329 MCAuto<DataArrayInt> pflSafe(pfl);
1330 MCAuto<DataArrayInt> mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end()));
1331 MCAuto<MEDCouplingUMesh> mzip(static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2)));
1332 MCAuto<DataArrayInt> arr2Safe(arr2);
1333 MCAuto<DataArrayInt> arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes()));
1334 MCAuto<DataArrayInt> pflSorted(pflSafe->deepCopy()); pflSorted->sort(true);
1335 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1336 throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !");
1337 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1339 MCAuto<DataArrayInt> o2n2(pflSafe->checkAndPreparePermutation());
1340 MCAuto<DataArrayInt> n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples()));
1341 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1350 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1352 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1353 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1354 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1355 MEDFileMesh *mPtr(mm);
1356 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1357 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m));
1360 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1362 ret->renumberCells(num->begin());
1367 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1369 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1370 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1371 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1372 MEDFileMesh *mPtr(mm);
1373 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1374 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m));
1377 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1379 ret->renumberCells(num->begin());
1384 void MEDCoupling::WriteMesh(const std::string& fileName, const MEDCoupling::MEDCouplingMesh *mesh, bool writeFromScratch)
1387 throw INTERP_KERNEL::Exception("WriteMesh : input mesh is null !");
1388 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1391 WriteUMesh(fileName,um,writeFromScratch);
1394 int mod=writeFromScratch?2:0;
1395 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1398 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1399 AssignStaticWritePropertiesTo(*mmu);
1400 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1401 mmu->write(fileName,mod);
1404 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1407 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1408 AssignStaticWritePropertiesTo(*mmc);
1409 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1410 mmc->write(fileName,mod);
1413 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1416 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1417 AssignStaticWritePropertiesTo(*mmc);
1418 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1419 mmc->write(fileName,mod);
1422 throw INTERP_KERNEL::Exception("WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1425 void MEDCoupling::WriteUMesh(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1428 throw INTERP_KERNEL::Exception("WriteUMesh : input mesh is null !");
1429 int mod=writeFromScratch?2:0;
1430 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1431 AssignStaticWritePropertiesTo(*m);
1432 MCAuto<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCopy()));
1433 m->setMeshAtLevel(0,mcpy,true);
1434 m->write(fileName,mod);
1437 void MEDCoupling::WriteUMeshDep(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1439 WriteUMesh(fileName,mesh,writeFromScratch);
1442 void MEDCoupling::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1444 std::string meshName(meshNameC);
1445 if(meshName.empty())
1446 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 !");
1447 int status=MEDLoaderBase::getStatusOfFile(fileName);
1448 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1450 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1451 throw INTERP_KERNEL::Exception(oss.str().c_str());
1453 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1454 AssignStaticWritePropertiesTo(*m);
1455 m->setGroupsFromScratch(0,meshes,true);
1456 m->setName(meshNameC);
1457 int mod=writeFromScratch?2:0;
1458 m->write(fileName,mod);
1461 void MEDCoupling::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1463 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1466 void MEDCoupling::WriteUMeshes(const std::string& fileName, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1468 int mod=writeFromScratch?2:0;
1469 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1470 AssignStaticWritePropertiesTo(*m);
1471 m->setMeshes(meshes,true);
1472 m->write(fileName,mod);
1475 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1477 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New());
1478 AssignStaticWritePropertiesTo(*ff);
1479 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1480 const MEDCouplingMesh *m(f2->getMesh());
1481 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1482 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1483 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1484 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1485 MCAuto<MEDFileMesh> mm;
1486 int mod=writeFromScratch?2:0;
1489 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1490 AssignStaticWritePropertiesTo(*mmu);
1491 MCAuto<DataArrayInt> o2n(um->getRenumArrForMEDFileFrmt());
1492 MCAuto<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1493 f2->renumberCells(o2n->begin(),false);
1494 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1495 mmu->setRenumFieldArr(0,n2o);
1496 ff->setFieldNoProfileSBT(f2);
1497 mmu->write(fileName,mod);
1501 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1502 AssignStaticWritePropertiesTo(*mmu);
1503 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1504 ff->setFieldNoProfileSBT(f2);
1505 mmu->write(fileName,mod);
1509 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1510 AssignStaticWritePropertiesTo(*mmc);
1511 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1512 ff->setFieldNoProfileSBT(f2);
1513 mmc->write(fileName,mod);
1517 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1518 AssignStaticWritePropertiesTo(*mmc);
1519 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1520 ff->setFieldNoProfileSBT(f2);
1521 mmc->write(fileName,mod);
1524 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1525 ff->write(fileName,0);
1528 void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1531 throw INTERP_KERNEL::Exception("WriteField : input field is NULL !");
1532 f->checkConsistencyLight();
1533 int status=MEDLoaderBase::getStatusOfFile(fileName);
1534 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1536 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1537 throw INTERP_KERNEL::Exception(oss.str().c_str());
1539 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1541 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
1545 std::vector<std::string> meshNames=GetMeshNames(fileName);
1547 throw INTERP_KERNEL::Exception("WriteField : trying to write a field with no mesh !");
1548 std::string fileNameCpp(f->getMesh()->getName());
1549 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1550 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
1553 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1554 AssignStaticWritePropertiesTo(*mm);
1555 const MEDFileMesh *mmPtr(mm);
1556 const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
1558 throw INTERP_KERNEL::Exception("WriteField : only umeshes are supported now !");
1559 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1560 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1562 throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !");
1563 MCAuto<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1564 f2->renumberCells(o2n->begin(),false);
1565 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1566 MCAuto<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
1567 if(f2->getTypeOfField()!=ON_NODES)
1569 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1570 DataArrayInt *part=0;
1571 bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
1572 MCAuto<DataArrayInt> partSafe(part);
1575 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 !";
1576 throw INTERP_KERNEL::Exception(oss.str().c_str());
1578 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1579 AssignStaticWritePropertiesTo(*f1ts);
1580 if(part->isIota(mread->getNumberOfCells()))
1581 f1ts->setFieldNoProfileSBT(f2);
1584 part->setName(f1ts->createNewNameOfPfl().c_str());
1585 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1587 f1ts->write(fileName,0);
1592 DataArrayInt *part=0;
1593 bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
1594 MCAuto<DataArrayInt> partSafe(part);
1597 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 !";
1598 throw INTERP_KERNEL::Exception(oss.str().c_str());
1600 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1601 AssignStaticWritePropertiesTo(*f1ts);
1602 if(part->isIota(mread->getNumberOfNodes()))
1603 f1ts->setFieldNoProfileSBT(f2);
1606 part->setName(f1ts->createNewNameOfPfl().c_str());
1607 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1609 f1ts->write(fileName,0);
1615 void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1617 WriteField(fileName,f,writeFromScratch);
1620 void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f)
1623 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1624 f->checkConsistencyLight();
1625 int status=MEDLoaderBase::getStatusOfFile(fileName);
1626 if(status!=MEDLoaderBase::EXIST_RW)
1628 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1629 throw INTERP_KERNEL::Exception(oss.str().c_str());
1631 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1632 AssignStaticWritePropertiesTo(*f1ts);
1633 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1636 MCAuto<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
1637 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1638 f2->renumberCells(o2n->begin(),false);
1639 f1ts->setFieldNoProfileSBT(f2);
1642 f1ts->setFieldNoProfileSBT(f);
1643 f1ts->write(fileName,0);