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 "MEDFileSafeCaller.txx"
25 #include "MEDFileMesh.hxx"
26 #include "MEDFileField.hxx"
27 #include "CellModel.hxx"
28 #include "MEDCouplingUMesh.hxx"
29 #include "MEDCouplingMemArray.hxx"
30 #include "MEDCouplingFieldDouble.hxx"
31 #include "MEDCouplingGaussLocalization.hxx"
34 #include "InterpKernelAutoPtr.hxx"
48 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
72 med_geometry_type typmainoeud[1] = { MED_NONE };
74 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
75 INTERP_KERNEL::NORM_SEG2,
76 INTERP_KERNEL::NORM_SEG3,
77 INTERP_KERNEL::NORM_SEG4,
78 INTERP_KERNEL::NORM_TRI3,
79 INTERP_KERNEL::NORM_QUAD4,
80 INTERP_KERNEL::NORM_TRI6,
81 INTERP_KERNEL::NORM_TRI7,
82 INTERP_KERNEL::NORM_QUAD8,
83 INTERP_KERNEL::NORM_QUAD9,
84 INTERP_KERNEL::NORM_TETRA4,
85 INTERP_KERNEL::NORM_PYRA5,
86 INTERP_KERNEL::NORM_PENTA6,
87 INTERP_KERNEL::NORM_HEXA8,
88 INTERP_KERNEL::NORM_HEXGP12,
89 INTERP_KERNEL::NORM_TETRA10,
90 INTERP_KERNEL::NORM_PYRA13,
91 INTERP_KERNEL::NORM_PENTA15,
92 INTERP_KERNEL::NORM_HEXA20,
93 INTERP_KERNEL::NORM_HEXA27,
94 INTERP_KERNEL::NORM_POLYGON,
95 INTERP_KERNEL::NORM_QPOLYG,
96 INTERP_KERNEL::NORM_POLYHED };
98 med_geometry_type typmai3[34] = { MED_POINT1,//0
134 double _EPS_FOR_NODE_COMP=1.e-12;
136 int _COMP_FOR_CELL=0;
140 using namespace MEDCoupling;
144 namespace MEDLoaderNS
146 int readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities);
147 void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity);
148 void writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch);
149 med_int getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName);
150 std::vector<std::string> getMeshNamesFid(med_idt fid);
159 * This method returns a first quick overview of mesh with name \a meshName into the file \a fileName.
160 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
161 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
163 int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities)
165 possibilities.clear();
166 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
169 char nommaa[MED_NAME_SIZE+1];
170 char maillage_description[MED_COMMENT_SIZE+1];
171 med_mesh_type type_maillage;
173 std::string trueMeshName;
174 med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
175 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
176 med_sorting_type sortingType;
178 med_axis_type axisType;
179 int naxis(MEDmeshnAxis(fid,meshId));
180 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
181 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
182 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
186 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
190 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
192 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
194 med_geometry_type curMedType=typmai[i];
195 med_bool changement,transformation;
196 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
197 int curNbOfElemF(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));//limitation
199 med_entity_type whichEntity;
200 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
203 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
204 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
211 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
212 possibilities.push_back(*it-ret);
219 med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName)
223 std::vector<std::string> meshes=getMeshNamesFid(fid);
225 throw INTERP_KERNEL::Exception("No mesh in file");
226 trueMeshName=meshes[0];
229 std::string meshNameStr(meshName);
230 std::vector<std::string> meshes=getMeshNamesFid(fid);
232 throw INTERP_KERNEL::Exception("No mesh in file");
233 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
234 if(iter==meshes.end())
236 std::ostringstream os2;
237 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
238 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
239 throw INTERP_KERNEL::Exception(os2.str().c_str());
241 trueMeshName=meshName;
242 return iter-meshes.begin()+1;
245 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
247 med_mesh_type type_maillage;
248 char maillage_description[MED_COMMENT_SIZE+1];
249 char dtunit[MED_COMMENT_SIZE+1];
252 char nommaa[MED_NAME_SIZE+1];
253 med_axis_type axistype;
254 med_sorting_type stype;
255 med_int n=MEDnMesh(fid);
256 std::vector<std::string> ret(n);
259 int naxis(MEDmeshnAxis(fid,i+1));
260 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
261 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
263 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
264 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
271 * This methods allows to merger all entities and to considerate only cell types.
273 void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
275 if(nbOfElemCell>=nbOfElemFace)
277 whichEntity=MED_CELL;
278 nbOfElem=nbOfElemCell;
282 whichEntity=MED_CELL;
283 nbOfElem=nbOfElemFace;
289 void MEDCoupling::AssignStaticWritePropertiesTo(MEDCoupling::MEDFileWritable& obj)
291 obj.setTooLongStrPolicy(_TOO_LONG_STR);
294 bool MEDCoupling::HasXDR()
303 std::string MEDCoupling::MEDFileVersionStr()
305 return std::string(MED_VERSION_STR);
308 void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
310 major=MED_NUM_MAJEUR;
311 minor=MED_NUM_MINEUR;
312 release=MED_NUM_RELEASE;
316 * 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.
318 void MEDCoupling::SetEpsilonForNodeComp(double val)
320 _EPS_FOR_NODE_COMP=val;
324 * 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.
326 void MEDCoupling::SetCompPolicyForCell(int val)
332 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
333 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
335 void MEDCoupling::SetTooLongStrPolicy(int val)
341 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
342 * It returns, in this order :
343 * - 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...
344 * - the mesh dimension
345 * - the space dimension
346 * - the number of nodes
348 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)
350 CheckFileForRead(fileName);
351 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
353 char nommaa[MED_NAME_SIZE+1];
354 char maillage_description[MED_COMMENT_SIZE+1];
355 med_mesh_type type_maillage;
356 std::string trueMeshName;
357 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
358 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
359 med_sorting_type sortingType;
361 med_axis_type axisType;
362 int naxis(MEDmeshnAxis(fid,meshId));
363 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
364 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
365 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
366 if(type_maillage!=MED_UNSTRUCTURED_MESH)
368 std::ostringstream oss; oss << "GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
369 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
370 throw INTERP_KERNEL::Exception(oss.str().c_str());
374 throw INTERP_KERNEL::Exception("GetUMeshGlobalInfo : multisteps on mesh not managed !");
377 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
379 std::vector<int> dims;
380 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
381 med_bool changement,transformation;
382 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
384 med_geometry_type curMedType=typmai[i];
385 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
388 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
389 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
390 dims.push_back(mdimCell);
391 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
394 int maxLev=*std::max_element(dims.begin(),dims.end());
395 int lowLev=*std::min_element(dims.begin(),dims.end());
396 int nbOfLevels=maxLev-lowLev+1;
397 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
398 for(std::size_t i=0;i<dims.size();i++)
400 ret[maxLev-dims[i]].push_back(geoTypes[i]);
402 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
406 void MEDCoupling::CheckFileForRead(const std::string& fileName)
408 MEDFileUtilities::CheckFileForRead(fileName);
411 std::vector<std::string> MEDCoupling::GetMeshNames(const std::string& fileName)
413 MEDCoupling::CheckFileForRead(fileName);
414 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
415 std::vector<std::string> ret=MEDLoaderNS::getMeshNamesFid(fid);
419 std::vector< std::pair<std::string,std::string> > MEDCoupling::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
421 MEDCoupling::CheckFileForRead(fileName);
422 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
423 med_int nbFields(MEDnField(fid));
424 std::vector<std::string> fields(nbFields);
425 med_field_type typcha;
426 for(int i=0;i<nbFields;i++)
428 med_int ncomp(MEDfieldnComponent(fid,i+1));
429 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
430 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
431 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
434 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
435 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
436 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
437 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
438 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
439 if(curFieldName==fieldName)
441 std::vector< std::pair<std::string,std::string> > ret(ncomp);
442 for(int j=0;j<ncomp;j++)
443 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
444 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
447 fields[i]=curFieldName;
449 std::ostringstream oss; oss << "GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
450 oss << "Possible field names are : " << std::endl;
451 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
452 throw INTERP_KERNEL::Exception(oss.str().c_str());
455 std::vector<std::string> MEDCoupling::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
457 MEDCoupling::CheckFileForRead(fileName);
458 std::vector<std::string> ret;
460 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
461 med_int nbFields=MEDnField(fid);
463 med_field_type typcha;
464 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
465 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
468 for(int i=0;i<nbFields;i++)
470 med_int ncomp(MEDfieldnComponent(fid,i+1));
471 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
472 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
474 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
475 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
476 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
477 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
478 if(curFieldName==fieldName)
479 ret.push_back(meshName);
484 std::vector<std::string> MEDCoupling::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
486 MEDCoupling::CheckFileForRead(fileName);
487 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
488 med_int nfam=MEDnFamily(fid,meshName.c_str());
489 std::vector<std::string> ret(nfam);
490 char nomfam[MED_NAME_SIZE+1];
492 for(int i=0;i<nfam;i++)
494 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
495 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
496 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
497 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
498 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
499 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
500 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
501 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
508 std::vector<std::string> MEDCoupling::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
510 MEDCoupling::CheckFileForRead(fileName);
511 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
512 med_int nfam=MEDnFamily(fid,meshName.c_str());
513 std::vector<std::string> ret;
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));
526 for(int j=0;j<ngro;j++)
528 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
536 std::vector<std::string> MEDCoupling::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
538 MEDCoupling::CheckFileForRead(fileName);
539 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
540 med_int nfam=MEDnFamily(fid,meshName.c_str());
541 std::vector<std::string> ret;
542 char nomfam[MED_NAME_SIZE+1];
545 for(int i=0;i<nfam && !found;i++)
547 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
548 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
549 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
550 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
551 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
552 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
553 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
554 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
555 found=(cur==famName);
557 for(int j=0;j<ngro;j++)
559 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
565 std::ostringstream oss;
566 oss << "GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
567 throw INTERP_KERNEL::Exception(oss.str().c_str());
573 std::vector<std::string> MEDCoupling::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
575 MEDCoupling::CheckFileForRead(fileName);
576 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
577 med_int nfam=MEDnFamily(fid,meshName.c_str());
578 std::vector<std::string> ret;
579 char nomfam[MED_NAME_SIZE+1];
581 for(int i=0;i<nfam;i++)
583 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
584 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
585 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
586 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
587 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
588 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
589 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
590 for(int j=0;j<ngro;j++)
592 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
593 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
600 std::vector<MEDCoupling::TypeOfField> MEDCoupling::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
602 std::vector<MEDCoupling::TypeOfField> ret;
603 MCAuto<MEDFileAnyTypeFieldMultiTS> fs(MEDFileAnyTypeFieldMultiTS::New(fileName,fieldName,false));
604 if(fs->getMeshName()!=meshName)
606 std::ostringstream oss; oss << "GetTypesOfField : The field \"" << fieldName << "\" in file \"" << fileName << "\" is not lying on mesh \"" << meshName << "\"";
607 oss << " The name of the mesh in file is \"" << fs->getMeshName() << "\"!";
608 throw INTERP_KERNEL::Exception(oss.str().c_str());
610 int nbTS(fs->getNumberOfTS());
613 for(int i=0;i<nbTS;i++)
615 MCAuto<MEDFileAnyTypeField1TS> f1ts(fs->getTimeStepAtPos(i));
616 std::vector<MEDCoupling::TypeOfField> tof(f1ts->getTypesOfFieldAvailable());
617 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=tof.begin();it!=tof.end();it++)
618 if(std::find(ret.begin(),ret.end(),*it)==ret.end())
621 // sort ret to put before ON_NODES then ON_CELLS then the remaining.
622 std::vector<MEDCoupling::TypeOfField> ret2;
623 if(std::find(ret.begin(),ret.end(),ON_NODES)!=ret.end())
624 ret2.push_back(ON_NODES);
625 if(std::find(ret.begin(),ret.end(),ON_CELLS)!=ret.end())
626 ret2.push_back(ON_CELLS);
627 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=ret.begin();it!=ret.end();it++)
628 if(*it!=ON_NODES && *it!=ON_CELLS)
633 std::vector<std::string> MEDCoupling::GetAllFieldNames(const std::string& fileName)
635 MEDCoupling::CheckFileForRead(fileName);
636 std::vector<std::string> ret;
637 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
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 MEDCoupling::CheckFileForRead(fileName);
659 std::vector<std::string> ret;
660 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
661 med_int nbFields=MEDnField(fid);
663 med_field_type typcha;
664 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
665 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
667 for(int i=0;i<nbFields;i++)
669 med_int ncomp(MEDfieldnComponent(fid,i+1));
670 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
671 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
672 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
675 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
676 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
677 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
679 if(curMeshName==meshName)
680 ret.push_back(curFieldName);
687 std::vector<std::string> MEDCoupling::GetFieldNamesOnMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName)
689 MEDCoupling::CheckFileForRead(fileName);
693 return GetCellFieldNamesOnMesh(fileName,meshName);
695 return GetNodeFieldNamesOnMesh(fileName,meshName);
697 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
701 std::vector<std::string> MEDCoupling::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
703 MEDCoupling::CheckFileForRead(fileName);
704 std::vector<std::string> ret;
705 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
706 med_int nbFields=MEDnField(fid);
708 med_field_type typcha;
709 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
710 med_int numdt=0,numo=0;
712 char pflname[MED_NAME_SIZE+1]="";
713 char locname[MED_NAME_SIZE+1]="";
714 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
715 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
716 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
720 for(int i=0;i<nbFields;i++)
722 med_int ncomp(MEDfieldnComponent(fid,i+1));
723 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
724 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
725 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
726 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
727 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
729 if(curMeshName==meshName)
732 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
736 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
737 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
738 pflname,&profilesize,locname,&nbi));
742 ret.push_back(curFieldName);
751 std::vector<std::string> MEDCoupling::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
753 MEDCoupling::CheckFileForRead(fileName);
754 std::vector<std::string> ret;
755 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
756 med_int nbFields=MEDnField(fid);
757 char pflname[MED_NAME_SIZE+1]="";
758 char locname[MED_NAME_SIZE+1]="";
760 med_field_type typcha;
761 med_int numdt=0,numo=0;
763 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
764 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
765 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
768 for(int i=0;i<nbFields;i++)
770 med_int ncomp(MEDfieldnComponent(fid,i+1));
771 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
772 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
774 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
775 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
776 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
780 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
781 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
782 pflname,&profilesize,locname,&nbi));
783 if(curMeshName==meshName && nbOfVal>0)
785 ret.push_back(curFieldName);
792 std::vector< std::pair< std::pair<int,int>, double> > MEDCoupling::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
794 MEDCoupling::CheckFileForRead(fileName);
795 std::vector< std::pair< std::pair<int,int>, double > > ret;
796 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
797 med_int nbFields=MEDnField(fid);
799 med_field_type typcha;
800 med_int numdt=0,numo=0;
802 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
803 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
804 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
807 std::ostringstream oss; oss << "GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
808 for(int i=0;i<nbFields;i++)
810 med_int ncomp(MEDfieldnComponent(fid,i+1));
811 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
812 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
814 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
815 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
816 if(curFieldName==fieldName)
818 for(int k=0;k<nbPdt;k++)
820 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
821 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
827 oss << "\"" << curFieldName << "\"";
828 if(i!=nbFields-1) oss << ", ";
832 throw INTERP_KERNEL::Exception(oss.str().c_str());
835 double MEDCoupling::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
837 MEDCoupling::CheckFileForRead(fileName);
838 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
839 med_int nbFields=MEDnField(fid);
841 med_field_type typcha;
842 med_int numdt=0,numo=0;
845 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
846 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
847 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
851 double ret=std::numeric_limits<double>::max();
852 for(int i=0;i<nbFields && !found;i++)
854 med_int ncomp(MEDfieldnComponent(fid,i+1));
855 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
856 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
858 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt));
859 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
860 if(curFieldName==fieldName)
863 for(int k=0;k<nbPdt;k++)
865 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
866 if(numdt==iteration && numo==order)
874 if(!found || !found2)
876 std::ostringstream oss;
877 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
878 throw INTERP_KERNEL::Exception(oss.str().c_str());
883 std::vector< std::pair<int,int> > MEDCoupling::GetFieldIterations(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
885 MEDCoupling::CheckFileForRead(fileName);
889 return GetCellFieldIterations(fileName,meshName,fieldName);
891 return GetNodeFieldIterations(fileName,meshName,fieldName);
893 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
897 std::vector< std::pair<int,int> > MEDCoupling::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
899 MEDCoupling::CheckFileForRead(fileName);
900 std::string meshNameCpp(meshName);
901 std::vector< std::pair<int,int> > ret;
902 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
903 med_int nbFields=MEDnField(fid);
905 med_field_type typcha;
906 med_int numdt=0,numo=0;
908 char pflname[MED_NAME_SIZE+1]="";
909 char locname[MED_NAME_SIZE+1]="";
910 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
911 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
912 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
915 std::ostringstream oss; oss << "GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
916 std::set<std::string> s2;
917 for(int i=0;i<nbFields;i++)
919 med_int ncomp(MEDfieldnComponent(fid,i+1));
920 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
921 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
923 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
924 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
925 if(curFieldName==fieldName)
928 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
930 for(int k=0;k<nbPdt;k++)
933 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
934 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
935 pflname,&profilesize,locname,&nbi));
936 std::string maa_ass_cpp(maa_ass);
939 if(meshNameCpp==maa_ass_cpp)
942 ret.push_back(std::make_pair(numdt,numo));
945 s2.insert(maa_ass_cpp);
952 oss << "\"" << curFieldName << "\"";
953 if(i!=nbFields-1) oss << ", ";
960 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
961 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
964 throw INTERP_KERNEL::Exception(oss.str().c_str());
969 std::vector< std::pair<int,int> > MEDCoupling::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
971 MEDCoupling::CheckFileForRead(fileName);
972 std::string meshNameCpp(meshName);
973 std::vector< std::pair<int,int> > ret;
974 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
975 med_int nbFields=MEDnField(fid);
977 med_field_type typcha;
978 med_int numdt=0,numo=0;
980 char pflname[MED_NAME_SIZE+1]="";
981 char locname[MED_NAME_SIZE+1]="";
982 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
983 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
984 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
987 std::ostringstream oss; oss << "GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
988 std::set<std::string> s2;
989 for(int i=0;i<nbFields;i++)
991 med_int ncomp(MEDfieldnComponent(fid,i+1));
992 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
993 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
995 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
996 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
997 if(curFieldName==fieldName)
999 for(int k=0;k<nbPdt;k++)
1001 int profilesize,nbi;
1002 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
1003 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1004 pflname,&profilesize,locname,&nbi));
1005 std::string maa_ass_cpp(maa_ass);
1008 if(meshNameCpp==maa_ass_cpp)
1009 { ret.push_back(std::make_pair(numdt,numo)); }
1011 s2.insert(maa_ass_cpp);
1017 oss << "\"" << curFieldName << "\"";
1018 if(i!=nbFields-1) oss << ", ";
1025 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1026 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1029 throw INTERP_KERNEL::Exception(oss.str().c_str());
1034 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1036 MEDCoupling::CheckFileForRead(fileName);
1037 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1038 MEDFileMesh *mmPtr(mm);
1039 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1041 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1042 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1045 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1046 return const_cast<MEDCouplingCMesh *>(ret);
1048 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1051 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1052 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1054 std::ostringstream oss; oss << "ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1055 throw INTERP_KERNEL::Exception(oss.str().c_str());
1058 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1060 MEDCoupling::CheckFileForRead(fileName);
1061 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1062 MEDFileMesh *mmPtr(mm);
1063 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1065 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1066 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1069 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1070 return const_cast<MEDCouplingCMesh *>(ret);
1072 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1075 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1076 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1078 std::ostringstream oss; oss << "ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1079 throw INTERP_KERNEL::Exception(oss.str().c_str());
1082 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1084 MEDCoupling::CheckFileForRead(fileName);
1085 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1086 MEDFileMesh *mmPtr(mm);
1087 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1090 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1091 throw INTERP_KERNEL::Exception(oss.str().c_str());
1093 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1096 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1098 MEDCoupling::CheckFileForRead(fileName);
1099 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1100 MEDFileMesh *mmPtr(mm);
1101 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1104 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1105 throw INTERP_KERNEL::Exception(oss.str().c_str());
1107 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1110 int MEDCoupling::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1112 MEDCoupling::CheckFileForRead(fileName);
1113 std::vector<int> poss;
1114 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1117 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1119 MEDCoupling::CheckFileForRead(fileName);
1120 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1121 MEDFileMesh *mmPtr(mm);
1122 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1125 std::ostringstream oss; oss << "ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1126 throw INTERP_KERNEL::Exception(oss.str().c_str());
1128 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1131 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1133 MEDCoupling::CheckFileForRead(fileName);
1134 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1135 MEDFileMesh *mmPtr(mm);
1136 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1139 std::ostringstream oss; oss << "ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1140 throw INTERP_KERNEL::Exception(oss.str().c_str());
1142 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1145 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)
1147 MEDCoupling::CheckFileForRead(fileName);
1151 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1153 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1155 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1157 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1159 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1163 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsOnSameMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1164 const std::vector<std::pair<int,int> >& its)
1167 return std::vector<MEDCoupling::MEDCouplingFieldDouble *>();
1168 MEDCoupling::CheckFileForRead(fileName);
1169 std::vector<MEDCoupling::MEDCouplingFieldDouble *> ret(its.size());
1170 std::vector< MCAuto<MEDCouplingFieldDouble> > retSafe(its.size());
1173 //Retrieving mesh of rank 0 and field on rank 0 too.
1174 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1175 MEDFileMesh *mmPtr(mm);
1176 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1178 throw INTERP_KERNEL::Exception("ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1179 MCAuto<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1180 const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1181 MCAuto<MEDCouplingUMesh> m2(m->clone(true));
1183 m2->renumberCells(o2n->begin(),true);
1185 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1187 MCAuto<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1188 MCAuto<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1190 retElt->renumberCells(o2n->begin(),true);
1191 retElt->setMesh(m2);
1195 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1196 ret[i]=retSafe[i].retn();
1200 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1201 const std::vector<std::pair<int,int> >& its)
1203 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1206 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1207 const std::vector<std::pair<int,int> >& its)
1209 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1212 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1213 const std::vector<std::pair<int,int> >& its)
1215 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1218 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1219 const std::vector<std::pair<int,int> >& its)
1221 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1224 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1226 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1227 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1228 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1229 MEDFileMesh *mPtr(mm);
1230 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1231 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_CELLS,m));
1234 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1236 ret->renumberCells(num->begin());
1241 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1243 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1244 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1245 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1246 MEDFileMesh *mPtr(mm);
1247 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_NODES,m));
1248 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1249 if(ff->getPflsReallyUsed().empty())
1253 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1255 ret->renumberCells(num->begin());
1260 DataArrayInt *pfl=0,*arr2=0;
1261 MCAuto<DataArrayDouble> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl));
1262 MCAuto<DataArrayInt> pflSafe(pfl);
1263 MCAuto<DataArrayInt> mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end()));
1264 MCAuto<MEDCouplingUMesh> mzip(static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2)));
1265 MCAuto<DataArrayInt> arr2Safe(arr2);
1266 MCAuto<DataArrayInt> arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes()));
1267 MCAuto<DataArrayInt> pflSorted(pflSafe->deepCopy()); pflSorted->sort(true);
1268 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1269 throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !");
1270 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1272 MCAuto<DataArrayInt> o2n2(pflSafe->checkAndPreparePermutation());
1273 MCAuto<DataArrayInt> n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples()));
1274 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1283 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1285 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1286 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1287 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1288 MEDFileMesh *mPtr(mm);
1289 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1290 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m));
1293 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1295 ret->renumberCells(num->begin());
1300 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1302 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1303 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1304 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1305 MEDFileMesh *mPtr(mm);
1306 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1307 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m));
1310 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1312 ret->renumberCells(num->begin());
1317 void MEDCoupling::WriteMesh(const std::string& fileName, const MEDCoupling::MEDCouplingMesh *mesh, bool writeFromScratch)
1320 throw INTERP_KERNEL::Exception("WriteMesh : input mesh is null !");
1321 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1324 WriteUMesh(fileName,um,writeFromScratch);
1327 int mod=writeFromScratch?2:0;
1328 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1331 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1332 AssignStaticWritePropertiesTo(*mmu);
1333 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1334 mmu->write(fileName,mod);
1337 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1340 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1341 AssignStaticWritePropertiesTo(*mmc);
1342 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1343 mmc->write(fileName,mod);
1346 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1349 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1350 AssignStaticWritePropertiesTo(*mmc);
1351 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1352 mmc->write(fileName,mod);
1355 throw INTERP_KERNEL::Exception("WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1358 void MEDCoupling::WriteUMesh(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1361 throw INTERP_KERNEL::Exception("WriteUMesh : input mesh is null !");
1362 int mod=writeFromScratch?2:0;
1363 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1364 AssignStaticWritePropertiesTo(*m);
1365 MCAuto<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCopy()));
1366 m->setMeshAtLevel(0,mcpy,true);
1367 m->write(fileName,mod);
1370 void MEDCoupling::WriteUMeshDep(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1372 WriteUMesh(fileName,mesh,writeFromScratch);
1375 void MEDCoupling::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1377 std::string meshName(meshNameC);
1378 if(meshName.empty())
1379 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 !");
1380 int status=MEDLoaderBase::getStatusOfFile(fileName);
1381 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1383 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1384 throw INTERP_KERNEL::Exception(oss.str().c_str());
1386 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1387 AssignStaticWritePropertiesTo(*m);
1388 m->setGroupsFromScratch(0,meshes,true);
1389 m->setName(meshNameC);
1390 int mod=writeFromScratch?2:0;
1391 m->write(fileName,mod);
1394 void MEDCoupling::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1396 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1399 void MEDCoupling::WriteUMeshes(const std::string& fileName, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1401 int mod=writeFromScratch?2:0;
1402 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1403 AssignStaticWritePropertiesTo(*m);
1404 m->setMeshes(meshes,true);
1405 m->write(fileName,mod);
1408 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1410 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New());
1411 AssignStaticWritePropertiesTo(*ff);
1412 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1413 const MEDCouplingMesh *m(f2->getMesh());
1414 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1415 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1416 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1417 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1418 MCAuto<MEDFileMesh> mm;
1419 int mod=writeFromScratch?2:0;
1422 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1423 AssignStaticWritePropertiesTo(*mmu);
1424 MCAuto<DataArrayInt> o2n(um->getRenumArrForMEDFileFrmt());
1425 MCAuto<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1426 f2->renumberCells(o2n->begin(),false);
1427 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1428 mmu->setRenumFieldArr(0,n2o);
1429 ff->setFieldNoProfileSBT(f2);
1430 mmu->write(fileName,mod);
1434 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1435 AssignStaticWritePropertiesTo(*mmu);
1436 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1437 ff->setFieldNoProfileSBT(f2);
1438 mmu->write(fileName,mod);
1442 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1443 AssignStaticWritePropertiesTo(*mmc);
1444 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1445 ff->setFieldNoProfileSBT(f2);
1446 mmc->write(fileName,mod);
1450 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1451 AssignStaticWritePropertiesTo(*mmc);
1452 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1453 ff->setFieldNoProfileSBT(f2);
1454 mmc->write(fileName,mod);
1457 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1458 ff->write(fileName,0);
1461 void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1464 throw INTERP_KERNEL::Exception("WriteField : input field is NULL !");
1465 f->checkConsistencyLight();
1466 int status=MEDLoaderBase::getStatusOfFile(fileName);
1467 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1469 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1470 throw INTERP_KERNEL::Exception(oss.str().c_str());
1472 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1474 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
1478 std::vector<std::string> meshNames=GetMeshNames(fileName);
1480 throw INTERP_KERNEL::Exception("WriteField : trying to write a field with no mesh !");
1481 std::string fileNameCpp(f->getMesh()->getName());
1482 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1483 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
1486 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1487 AssignStaticWritePropertiesTo(*mm);
1488 const MEDFileMesh *mmPtr(mm);
1489 const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
1491 throw INTERP_KERNEL::Exception("WriteField : only umeshes are supported now !");
1492 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1493 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1495 throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !");
1496 MCAuto<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1497 f2->renumberCells(o2n->begin(),false);
1498 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1499 MCAuto<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
1500 if(f2->getTypeOfField()!=ON_NODES)
1502 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1503 DataArrayInt *part=0;
1504 bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
1505 MCAuto<DataArrayInt> partSafe(part);
1508 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 !";
1509 throw INTERP_KERNEL::Exception(oss.str().c_str());
1511 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1512 AssignStaticWritePropertiesTo(*f1ts);
1513 if(part->isIota(mread->getNumberOfCells()))
1514 f1ts->setFieldNoProfileSBT(f2);
1517 part->setName(f1ts->createNewNameOfPfl().c_str());
1518 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1520 f1ts->write(fileName,0);
1525 DataArrayInt *part=0;
1526 bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
1527 MCAuto<DataArrayInt> partSafe(part);
1530 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 !";
1531 throw INTERP_KERNEL::Exception(oss.str().c_str());
1533 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1534 AssignStaticWritePropertiesTo(*f1ts);
1535 if(part->isIota(mread->getNumberOfNodes()))
1536 f1ts->setFieldNoProfileSBT(f2);
1539 part->setName(f1ts->createNewNameOfPfl().c_str());
1540 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1542 f1ts->write(fileName,0);
1548 void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1550 WriteField(fileName,f,writeFromScratch);
1553 void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f)
1556 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1557 f->checkConsistencyLight();
1558 int status=MEDLoaderBase::getStatusOfFile(fileName);
1559 if(status!=MEDLoaderBase::EXIST_RW)
1561 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1562 throw INTERP_KERNEL::Exception(oss.str().c_str());
1564 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1565 AssignStaticWritePropertiesTo(*f1ts);
1566 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1569 MCAuto<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
1570 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1571 f2->renumberCells(o2n->begin(),false);
1572 f1ts->setFieldNoProfileSBT(f2);
1575 f1ts->setFieldNoProfileSBT(f);
1576 f1ts->write(fileName,0);