1 // Copyright (C) 2007-2015 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 "MEDFileMesh.hxx"
25 #include "MEDFileField.hxx"
26 #include "CellModel.hxx"
27 #include "MEDCouplingUMesh.hxx"
28 #include "MEDCouplingMemArray.hxx"
29 #include "MEDCouplingFieldDouble.hxx"
30 #include "MEDCouplingGaussLocalization.hxx"
31 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
33 #include "InterpKernelAutoPtr.hxx"
46 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
70 med_geometry_type typmainoeud[1] = { MED_NONE };
72 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
73 INTERP_KERNEL::NORM_SEG2,
74 INTERP_KERNEL::NORM_SEG3,
75 INTERP_KERNEL::NORM_SEG4,
76 INTERP_KERNEL::NORM_TRI3,
77 INTERP_KERNEL::NORM_QUAD4,
78 INTERP_KERNEL::NORM_TRI6,
79 INTERP_KERNEL::NORM_TRI7,
80 INTERP_KERNEL::NORM_QUAD8,
81 INTERP_KERNEL::NORM_QUAD9,
82 INTERP_KERNEL::NORM_TETRA4,
83 INTERP_KERNEL::NORM_PYRA5,
84 INTERP_KERNEL::NORM_PENTA6,
85 INTERP_KERNEL::NORM_HEXA8,
86 INTERP_KERNEL::NORM_HEXGP12,
87 INTERP_KERNEL::NORM_TETRA10,
88 INTERP_KERNEL::NORM_PYRA13,
89 INTERP_KERNEL::NORM_PENTA15,
90 INTERP_KERNEL::NORM_HEXA20,
91 INTERP_KERNEL::NORM_HEXA27,
92 INTERP_KERNEL::NORM_POLYGON,
93 INTERP_KERNEL::NORM_QPOLYG,
94 INTERP_KERNEL::NORM_POLYHED };
96 med_geometry_type typmai3[34] = { MED_POINT1,//0
132 double MEDLoader::_EPS_FOR_NODE_COMP=1.e-12;
134 int MEDLoader::_COMP_FOR_CELL=0;
136 int MEDLoader::_TOO_LONG_STR=0;
138 using namespace ParaMEDMEM;
142 namespace MEDLoaderNS
144 int readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities);
145 void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity);
146 void writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch);
147 med_int getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName);
148 std::vector<std::string> getMeshNamesFid(med_idt fid);
157 * This method returns a first quick overview of mesh with name \a meshName into the file \a fileName.
158 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
159 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
161 int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities)
163 possibilities.clear();
164 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
167 char nommaa[MED_NAME_SIZE+1];
168 char maillage_description[MED_COMMENT_SIZE+1];
169 med_mesh_type type_maillage;
171 std::string trueMeshName;
172 med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
173 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
174 med_sorting_type sortingType;
176 med_axis_type axisType;
177 int naxis=MEDmeshnAxis(fid,meshId);
178 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
179 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
180 MEDmeshInfo(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit);
184 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
188 MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
190 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
192 med_geometry_type curMedType=typmai[i];
193 med_bool changement,transformation;
194 int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
195 int curNbOfElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);//limitation
197 med_entity_type whichEntity;
198 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
201 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
202 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
209 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
210 possibilities.push_back(*it-ret);
217 med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName)
221 std::vector<std::string> meshes=getMeshNamesFid(fid);
223 throw INTERP_KERNEL::Exception("No mesh in file");
224 trueMeshName=meshes[0];
227 std::string meshNameStr(meshName);
228 std::vector<std::string> meshes=getMeshNamesFid(fid);
230 throw INTERP_KERNEL::Exception("No mesh in file");
231 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
232 if(iter==meshes.end())
234 std::ostringstream os2;
235 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
236 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
237 throw INTERP_KERNEL::Exception(os2.str().c_str());
239 trueMeshName=meshName;
240 return iter-meshes.begin()+1;
243 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
245 med_mesh_type type_maillage;
246 char maillage_description[MED_COMMENT_SIZE+1];
247 char dtunit[MED_COMMENT_SIZE+1];
250 char nommaa[MED_NAME_SIZE+1];
251 med_axis_type axistype;
252 med_sorting_type stype;
253 med_int n=MEDnMesh(fid);
254 std::vector<std::string> ret(n);
257 int naxis=MEDmeshnAxis(fid,i+1);
258 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
259 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
261 MEDmeshInfo(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit);
262 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
269 * This methods allows to merger all entities and to considerate only cell types.
271 void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
273 if(nbOfElemCell>=nbOfElemFace)
275 whichEntity=MED_CELL;
276 nbOfElem=nbOfElemCell;
280 whichEntity=MED_CELL;
281 nbOfElem=nbOfElemFace;
287 void MEDLoader::AssignStaticWritePropertiesTo(ParaMEDMEM::MEDFileWritable& obj)
289 obj.setTooLongStrPolicy(_TOO_LONG_STR);
292 bool MEDLoader::HasXDR()
301 std::string MEDLoader::MEDFileVersionStr()
303 return std::string(MED_VERSION_STR);
306 void MEDLoader::MEDFileVersion(int& major, int& minor, int& release)
308 major=MED_NUM_MAJEUR;
309 minor=MED_NUM_MINEUR;
310 release=MED_NUM_RELEASE;
314 * 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.
316 void MEDLoader::SetEpsilonForNodeComp(double val)
318 _EPS_FOR_NODE_COMP=val;
322 * 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.
324 void MEDLoader::SetCompPolicyForCell(int val)
330 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
331 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
333 void MEDLoader::SetTooLongStrPolicy(int val)
339 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
340 * It returns, in this order :
341 * - 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...
342 * - the mesh dimension
343 * - the space dimension
344 * - the number of nodes
346 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > MEDLoader::GetUMeshGlobalInfo(const std::string& fileName, const std::string& meshName, int &meshDim, int& spaceDim, int& numberOfNodes)
348 CheckFileForRead(fileName);
349 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
351 char nommaa[MED_NAME_SIZE+1];
352 char maillage_description[MED_COMMENT_SIZE+1];
353 med_mesh_type type_maillage;
354 std::string trueMeshName;
355 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
356 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
357 med_sorting_type sortingType;
359 med_axis_type axisType;
360 int naxis=MEDmeshnAxis(fid,meshId);
361 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
362 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
363 MEDmeshInfo(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit);
364 if(type_maillage!=MED_UNSTRUCTURED_MESH)
366 std::ostringstream oss; oss << "MEDLoader::GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
367 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
368 throw INTERP_KERNEL::Exception(oss.str().c_str());
372 throw INTERP_KERNEL::Exception("MEDLoader::GetUMeshGlobalInfo : multisteps on mesh not managed !");
375 MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
377 std::vector<int> dims;
378 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
379 med_bool changement,transformation;
380 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
382 med_geometry_type curMedType=typmai[i];
383 int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
386 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
387 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
388 dims.push_back(mdimCell);
389 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
392 int maxLev=*std::max_element(dims.begin(),dims.end());
393 int lowLev=*std::min_element(dims.begin(),dims.end());
394 int nbOfLevels=maxLev-lowLev+1;
395 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
396 for(std::size_t i=0;i<dims.size();i++)
398 ret[maxLev-dims[i]].push_back(geoTypes[i]);
400 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
404 void MEDLoader::CheckFileForRead(const std::string& fileName)
406 MEDFileUtilities::CheckFileForRead(fileName);
409 std::vector<std::string> MEDLoader::GetMeshNames(const std::string& fileName)
411 CheckFileForRead(fileName);
412 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
413 std::vector<std::string> ret=MEDLoaderNS::getMeshNamesFid(fid);
417 std::vector< std::pair<std::string,std::string> > MEDLoader::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
419 CheckFileForRead(fileName);
420 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
421 med_int nbFields=MEDnField(fid);
422 std::vector<std::string> fields(nbFields);
423 med_field_type typcha;
424 for(int i=0;i<nbFields;i++)
426 med_int ncomp=MEDfieldnComponent(fid,i+1);
427 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
428 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
429 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
432 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
433 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
434 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
435 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
436 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
437 if(curFieldName==fieldName)
439 std::vector< std::pair<std::string,std::string> > ret(ncomp);
440 for(int j=0;j<ncomp;j++)
441 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
442 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
445 fields[i]=curFieldName;
447 std::ostringstream oss; oss << "MEDLoader::GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
448 oss << "Possible field names are : " << std::endl;
449 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
450 throw INTERP_KERNEL::Exception(oss.str().c_str());
453 std::vector<std::string> MEDLoader::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
455 CheckFileForRead(fileName);
456 std::vector<std::string> ret;
458 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
459 med_int nbFields=MEDnField(fid);
461 med_field_type typcha;
462 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
463 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
466 for(int i=0;i<nbFields;i++)
468 med_int ncomp=MEDfieldnComponent(fid,i+1);
469 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
470 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
472 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
473 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
474 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
475 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
476 if(curFieldName==fieldName)
477 ret.push_back(meshName);
482 std::vector<std::string> MEDLoader::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
484 CheckFileForRead(fileName);
485 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
486 med_int nfam=MEDnFamily(fid,meshName.c_str());
487 std::vector<std::string> ret(nfam);
488 char nomfam[MED_NAME_SIZE+1];
490 for(int i=0;i<nfam;i++)
492 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
493 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
494 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
495 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
496 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
497 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
498 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
499 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
506 std::vector<std::string> MEDLoader::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
508 CheckFileForRead(fileName);
509 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
510 med_int nfam=MEDnFamily(fid,meshName.c_str());
511 std::vector<std::string> ret;
512 char nomfam[MED_NAME_SIZE+1];
514 for(int i=0;i<nfam;i++)
516 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
517 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
518 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
519 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
520 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
521 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
522 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
523 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
524 for(int j=0;j<ngro;j++)
526 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
534 std::vector<std::string> MEDLoader::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
536 CheckFileForRead(fileName);
537 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
538 med_int nfam=MEDnFamily(fid,meshName.c_str());
539 std::vector<std::string> ret;
540 char nomfam[MED_NAME_SIZE+1];
543 for(int i=0;i<nfam && !found;i++)
545 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
546 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
547 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
548 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
549 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
550 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
551 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
552 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
553 found=(cur==famName);
555 for(int j=0;j<ngro;j++)
557 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
563 std::ostringstream oss;
564 oss << "MEDLoader::GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
565 throw INTERP_KERNEL::Exception(oss.str().c_str());
571 std::vector<std::string> MEDLoader::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
573 CheckFileForRead(fileName);
574 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
575 med_int nfam=MEDnFamily(fid,meshName.c_str());
576 std::vector<std::string> ret;
577 char nomfam[MED_NAME_SIZE+1];
579 for(int i=0;i<nfam;i++)
581 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
582 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
583 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
584 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
585 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
586 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
587 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
588 for(int j=0;j<ngro;j++)
590 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
591 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
598 std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
600 std::vector<ParaMEDMEM::TypeOfField> ret;
601 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> fs(MEDFileAnyTypeFieldMultiTS::New(fileName,fieldName,false));
602 if(fs->getMeshName()!=meshName)
604 std::ostringstream oss; oss << "MEDLoader::GetTypesOfField : The field \"" << fieldName << "\" in file \"" << fileName << "\" is not lying on mesh \"" << meshName << "\"";
605 oss << " The name of the mesh in file is \"" << fs->getMeshName() << "\"!";
606 throw INTERP_KERNEL::Exception(oss.str().c_str());
608 int nbTS(fs->getNumberOfTS());
611 for(int i=0;i<nbTS;i++)
613 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1ts(fs->getTimeStepAtPos(i));
614 std::vector<ParaMEDMEM::TypeOfField> tof(f1ts->getTypesOfFieldAvailable());
615 for(std::vector<ParaMEDMEM::TypeOfField>::const_iterator it=tof.begin();it!=tof.end();it++)
616 if(std::find(ret.begin(),ret.end(),*it)==ret.end())
619 // sort ret to put before ON_NODES then ON_CELLS then the remaining.
620 std::vector<ParaMEDMEM::TypeOfField> ret2;
621 if(std::find(ret.begin(),ret.end(),ON_NODES)!=ret.end())
622 ret2.push_back(ON_NODES);
623 if(std::find(ret.begin(),ret.end(),ON_CELLS)!=ret.end())
624 ret2.push_back(ON_CELLS);
625 for(std::vector<ParaMEDMEM::TypeOfField>::const_iterator it=ret.begin();it!=ret.end();it++)
626 if(*it!=ON_NODES && *it!=ON_CELLS)
631 std::vector<std::string> MEDLoader::GetAllFieldNames(const std::string& fileName)
633 CheckFileForRead(fileName);
634 std::vector<std::string> ret;
635 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
636 med_int nbFields=MEDnField(fid);
637 med_field_type typcha;
638 for(int i=0;i<nbFields;i++)
640 med_int ncomp=MEDfieldnComponent(fid,i+1);
641 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
642 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
643 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
644 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
645 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
648 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
649 ret.push_back(std::string(nomcha));
654 std::vector<std::string> MEDLoader::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
656 CheckFileForRead(fileName);
657 std::vector<std::string> ret;
658 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
659 med_int nbFields=MEDnField(fid);
661 med_field_type typcha;
662 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
663 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
665 for(int i=0;i<nbFields;i++)
667 med_int ncomp=MEDfieldnComponent(fid,i+1);
668 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
669 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
670 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
673 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
674 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
675 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
677 if(curMeshName==meshName)
678 ret.push_back(curFieldName);
685 std::vector<std::string> MEDLoader::GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName)
687 CheckFileForRead(fileName);
691 return GetCellFieldNamesOnMesh(fileName,meshName);
693 return GetNodeFieldNamesOnMesh(fileName,meshName);
695 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
699 std::vector<std::string> MEDLoader::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
701 CheckFileForRead(fileName);
702 std::vector<std::string> ret;
703 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
704 med_int nbFields=MEDnField(fid);
706 med_field_type typcha;
707 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
708 med_int numdt=0,numo=0;
710 char pflname[MED_NAME_SIZE+1]="";
711 char locname[MED_NAME_SIZE+1]="";
712 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
713 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
714 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
718 for(int i=0;i<nbFields;i++)
720 med_int ncomp=MEDfieldnComponent(fid,i+1);
721 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
722 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
723 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
724 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
725 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
727 if(curMeshName==meshName)
730 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
734 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
735 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
736 pflname,&profilesize,locname,&nbi);
740 ret.push_back(curFieldName);
749 std::vector<std::string> MEDLoader::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
751 CheckFileForRead(fileName);
752 std::vector<std::string> ret;
753 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
754 med_int nbFields=MEDnField(fid);
755 char pflname[MED_NAME_SIZE+1]="";
756 char locname[MED_NAME_SIZE+1]="";
758 med_field_type typcha;
759 med_int numdt=0,numo=0;
761 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
762 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
763 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
766 for(int i=0;i<nbFields;i++)
768 med_int ncomp=MEDfieldnComponent(fid,i+1);
769 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
770 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
772 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
773 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
774 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
778 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
779 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
780 pflname,&profilesize,locname,&nbi);
781 if(curMeshName==meshName && nbOfVal>0)
783 ret.push_back(curFieldName);
790 std::vector< std::pair< std::pair<int,int>, double> > MEDLoader::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
792 CheckFileForRead(fileName);
793 std::vector< std::pair< std::pair<int,int>, double > > ret;
794 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
795 med_int nbFields=MEDnField(fid);
797 med_field_type typcha;
798 med_int numdt=0,numo=0;
800 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
801 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
802 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
805 std::ostringstream oss; oss << "MEDLoader::GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
806 for(int i=0;i<nbFields;i++)
808 med_int ncomp=MEDfieldnComponent(fid,i+1);
809 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
810 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
812 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
813 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
814 if(curFieldName==fieldName)
816 for(int k=0;k<nbPdt;k++)
818 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
819 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
825 oss << "\"" << curFieldName << "\"";
826 if(i!=nbFields-1) oss << ", ";
830 throw INTERP_KERNEL::Exception(oss.str().c_str());
833 double MEDLoader::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
835 CheckFileForRead(fileName);
836 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
837 med_int nbFields=MEDnField(fid);
839 med_field_type typcha;
840 med_int numdt=0,numo=0;
843 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
844 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
845 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
849 double ret=std::numeric_limits<double>::max();
850 for(int i=0;i<nbFields && !found;i++)
852 med_int ncomp=MEDfieldnComponent(fid,i+1);
853 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
854 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
856 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt);
857 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
858 if(curFieldName==fieldName)
861 for(int k=0;k<nbPdt;k++)
863 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
864 if(numdt==iteration && numo==order)
872 if(!found || !found2)
874 std::ostringstream oss;
875 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
876 throw INTERP_KERNEL::Exception(oss.str().c_str());
881 std::vector< std::pair<int,int> > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
883 CheckFileForRead(fileName);
887 return GetCellFieldIterations(fileName,meshName,fieldName);
889 return GetNodeFieldIterations(fileName,meshName,fieldName);
891 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
895 std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
897 CheckFileForRead(fileName);
898 std::string meshNameCpp(meshName);
899 std::vector< std::pair<int,int> > ret;
900 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
901 med_int nbFields=MEDnField(fid);
903 med_field_type typcha;
904 med_int numdt=0,numo=0;
906 char pflname[MED_NAME_SIZE+1]="";
907 char locname[MED_NAME_SIZE+1]="";
908 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
909 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
910 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
913 std::ostringstream oss; oss << "MEDLoader::GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
914 std::set<std::string> s2;
915 for(int i=0;i<nbFields;i++)
917 med_int ncomp=MEDfieldnComponent(fid,i+1);
918 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
919 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
921 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
922 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
923 if(curFieldName==fieldName)
926 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
928 for(int k=0;k<nbPdt;k++)
931 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
932 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
933 pflname,&profilesize,locname,&nbi);
934 std::string maa_ass_cpp(maa_ass);
937 if(meshNameCpp==maa_ass_cpp)
940 ret.push_back(std::make_pair(numdt,numo));
943 s2.insert(maa_ass_cpp);
950 oss << "\"" << curFieldName << "\"";
951 if(i!=nbFields-1) oss << ", ";
958 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
959 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
962 throw INTERP_KERNEL::Exception(oss.str().c_str());
967 std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
969 CheckFileForRead(fileName);
970 std::string meshNameCpp(meshName);
971 std::vector< std::pair<int,int> > ret;
972 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
973 med_int nbFields=MEDnField(fid);
975 med_field_type typcha;
976 med_int numdt=0,numo=0;
978 char pflname[MED_NAME_SIZE+1]="";
979 char locname[MED_NAME_SIZE+1]="";
980 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
981 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
982 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
985 std::ostringstream oss; oss << "MEDLoader::GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
986 std::set<std::string> s2;
987 for(int i=0;i<nbFields;i++)
989 med_int ncomp=MEDfieldnComponent(fid,i+1);
990 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
991 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
993 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
994 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
995 if(curFieldName==fieldName)
997 for(int k=0;k<nbPdt;k++)
1000 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
1001 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1002 pflname,&profilesize,locname,&nbi);
1003 std::string maa_ass_cpp(maa_ass);
1006 if(meshNameCpp==maa_ass_cpp)
1007 { ret.push_back(std::make_pair(numdt,numo)); }
1009 s2.insert(maa_ass_cpp);
1015 oss << "\"" << curFieldName << "\"";
1016 if(i!=nbFields-1) oss << ", ";
1023 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1024 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1027 throw INTERP_KERNEL::Exception(oss.str().c_str());
1032 ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1034 CheckFileForRead(fileName);
1035 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1036 MEDFileMesh *mmPtr(mm);
1037 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1039 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1040 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1043 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1044 return const_cast<MEDCouplingCMesh *>(ret);
1046 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1049 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1050 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1052 std::ostringstream oss; oss << "MEDLoader::ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1053 throw INTERP_KERNEL::Exception(oss.str().c_str());
1056 ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1058 CheckFileForRead(fileName);
1059 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1060 MEDFileMesh *mmPtr(mm);
1061 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1063 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1064 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1067 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1068 return const_cast<MEDCouplingCMesh *>(ret);
1070 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1073 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1074 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1076 std::ostringstream oss; oss << "MEDLoader::ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1077 throw INTERP_KERNEL::Exception(oss.str().c_str());
1080 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1082 CheckFileForRead(fileName);
1083 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1084 MEDFileMesh *mmPtr(mm);
1085 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1088 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1089 throw INTERP_KERNEL::Exception(oss.str().c_str());
1091 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1094 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1096 CheckFileForRead(fileName);
1097 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1098 MEDFileMesh *mmPtr(mm);
1099 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1102 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1103 throw INTERP_KERNEL::Exception(oss.str().c_str());
1105 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1108 int MEDLoader::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1110 CheckFileForRead(fileName);
1111 std::vector<int> poss;
1112 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1115 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1117 CheckFileForRead(fileName);
1118 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1119 MEDFileMesh *mmPtr(mm);
1120 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1123 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1124 throw INTERP_KERNEL::Exception(oss.str().c_str());
1126 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1129 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1131 CheckFileForRead(fileName);
1132 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1133 MEDFileMesh *mmPtr(mm);
1134 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1137 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1138 throw INTERP_KERNEL::Exception(oss.str().c_str());
1140 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1143 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadField(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1145 CheckFileForRead(fileName);
1149 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1151 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1153 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1155 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1157 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1161 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsOnSameMesh(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1162 const std::vector<std::pair<int,int> >& its)
1165 return std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>();
1166 CheckFileForRead(fileName);
1167 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> ret(its.size());
1168 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> > retSafe(its.size());
1171 //Retrieving mesh of rank 0 and field on rank 0 too.
1172 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1173 MEDFileMesh *mmPtr(mm);
1174 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1176 throw INTERP_KERNEL::Exception("MEDLoader::ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1177 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1178 const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1179 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m2(m->clone(true));
1181 m2->renumberCells(o2n->begin(),true);
1183 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1185 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1186 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1188 retElt->renumberCells(o2n->begin(),true);
1189 retElt->setMesh(m2);
1193 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1194 ret[i]=retSafe[i].retn();
1198 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1199 const std::vector<std::pair<int,int> >& its)
1201 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1204 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1205 const std::vector<std::pair<int,int> >& its)
1207 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1210 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1211 const std::vector<std::pair<int,int> >& its)
1213 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1216 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1217 const std::vector<std::pair<int,int> >& its)
1219 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1222 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1224 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1225 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1226 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1227 MEDFileMesh *mPtr(mm);
1228 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1229 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_CELLS,m);
1232 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1234 ret->renumberCells(num->begin());
1239 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1241 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1242 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1243 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1244 MEDFileMesh *mPtr(mm);
1245 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_NODES,m);
1246 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1247 if(ff->getPflsReallyUsed().empty())
1251 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1253 ret->renumberCells(num->begin());
1258 DataArrayInt *pfl=0,*arr2=0;
1259 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl);
1260 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflSafe(pfl);
1261 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> mp=m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end());
1262 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mzip=static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2));
1263 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2Safe(arr2);
1264 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes());
1265 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflSorted(pflSafe->deepCpy()); pflSorted->sort(true);
1266 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1267 throw INTERP_KERNEL::Exception("MEDLoader::ReadFieldNode : not implemented yet !");
1268 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1270 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n2=pflSafe->checkAndPreparePermutation();
1271 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o2=o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples());
1272 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1281 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1283 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1284 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1285 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1286 MEDFileMesh *mPtr(mm);
1287 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1288 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m);
1291 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1293 ret->renumberCells(num->begin());
1298 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1300 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1301 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1302 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1303 MEDFileMesh *mPtr(mm);
1304 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1305 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m);
1308 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1310 ret->renumberCells(num->begin());
1315 void MEDLoader::WriteMesh(const std::string& fileName, const ParaMEDMEM::MEDCouplingMesh *mesh, bool writeFromScratch)
1318 throw INTERP_KERNEL::Exception("MEDLoader::WriteMesh : input mesh is null !");
1319 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1322 WriteUMesh(fileName,um,writeFromScratch);
1325 int mod=writeFromScratch?2:0;
1326 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1329 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
1330 AssignStaticWritePropertiesTo(*mmu);
1331 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1332 mmu->write(fileName,mod);
1335 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1338 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc(MEDFileCMesh::New());
1339 AssignStaticWritePropertiesTo(*mmc);
1340 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1341 mmc->write(fileName,mod);
1344 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1347 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1348 AssignStaticWritePropertiesTo(*mmc);
1349 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1350 mmc->write(fileName,mod);
1353 throw INTERP_KERNEL::Exception("MEDLoader::WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1356 void MEDLoader::WriteUMesh(const std::string& fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch)
1359 throw INTERP_KERNEL::Exception("MEDLoader::WriteUMesh : input mesh is null !");
1360 int mod=writeFromScratch?2:0;
1361 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
1362 AssignStaticWritePropertiesTo(*m);
1363 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCpy()));
1364 m->setMeshAtLevel(0,mcpy,true);
1365 m->write(fileName,mod);
1368 void MEDLoader::WriteUMeshDep(const std::string& fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch)
1370 MEDLoader::WriteUMesh(fileName,mesh,writeFromScratch);
1373 void MEDLoader::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1375 std::string meshName(meshNameC);
1376 if(meshName.empty())
1377 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 !");
1378 int status=MEDLoaderBase::getStatusOfFile(fileName);
1379 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1381 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1382 throw INTERP_KERNEL::Exception(oss.str().c_str());
1384 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
1385 AssignStaticWritePropertiesTo(*m);
1386 m->setGroupsFromScratch(0,meshes,true);
1387 m->setName(meshNameC);
1388 int mod=writeFromScratch?2:0;
1389 m->write(fileName,mod);
1392 void MEDLoader::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1394 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1397 void MEDLoader::WriteUMeshes(const std::string& fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1399 int mod=writeFromScratch?2:0;
1400 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
1401 AssignStaticWritePropertiesTo(*m);
1402 m->setMeshes(meshes,true);
1403 m->write(fileName,mod);
1406 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1408 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff(MEDFileField1TS::New());
1409 MEDLoader::AssignStaticWritePropertiesTo(*ff);
1410 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1411 const MEDCouplingMesh *m(f2->getMesh());
1412 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1413 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1414 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1415 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1416 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
1417 int mod=writeFromScratch?2:0;
1420 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
1421 MEDLoader::AssignStaticWritePropertiesTo(*mmu);
1422 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(um->getRenumArrForMEDFileFrmt());
1423 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1424 f2->renumberCells(o2n->begin(),false);
1425 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1426 mmu->setRenumFieldArr(0,n2o);
1427 ff->setFieldNoProfileSBT(f2);
1428 mmu->write(fileName,mod);
1432 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
1433 MEDLoader::AssignStaticWritePropertiesTo(*mmu);
1434 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1435 ff->setFieldNoProfileSBT(f2);
1436 mmu->write(fileName,mod);
1440 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc(MEDFileCMesh::New());
1441 MEDLoader::AssignStaticWritePropertiesTo(*mmc);
1442 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1443 ff->setFieldNoProfileSBT(f2);
1444 mmc->write(fileName,mod);
1448 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1449 MEDLoader::AssignStaticWritePropertiesTo(*mmc);
1450 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1451 ff->setFieldNoProfileSBT(f2);
1452 mmc->write(fileName,mod);
1455 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1456 ff->write(fileName,0);
1459 void MEDLoader::WriteField(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1462 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : input field is NULL !");
1463 f->checkCoherency();
1464 int status=MEDLoaderBase::getStatusOfFile(fileName);
1465 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1467 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1468 throw INTERP_KERNEL::Exception(oss.str().c_str());
1470 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1472 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
1476 std::vector<std::string> meshNames=GetMeshNames(fileName);
1478 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : trying to write a field with no mesh !");
1479 std::string fileNameCpp(f->getMesh()->getName());
1480 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1481 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
1484 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1485 AssignStaticWritePropertiesTo(*mm);
1486 const MEDFileMesh *mmPtr(mm);
1487 const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
1489 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : only umeshes are supported now !");
1490 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1491 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1493 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : only umesh in input field supported !");
1494 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1495 f2->renumberCells(o2n->begin(),false);
1496 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1497 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
1498 if(f2->getTypeOfField()!=ON_NODES)
1500 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1501 DataArrayInt *part=0;
1502 bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
1503 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> partSafe(part);
1506 std::ostringstream oss; oss << "MEDLoader::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 !";
1507 throw INTERP_KERNEL::Exception(oss.str().c_str());
1509 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1510 AssignStaticWritePropertiesTo(*f1ts);
1511 if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfCells())
1512 f1ts->setFieldNoProfileSBT(f2);
1515 part->setName(f1ts->createNewNameOfPfl().c_str());
1516 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1518 f1ts->write(fileName,0);
1523 DataArrayInt *part=0;
1524 bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
1525 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> partSafe(part);
1528 std::ostringstream oss; oss << "MEDLoader::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 !";
1529 throw INTERP_KERNEL::Exception(oss.str().c_str());
1531 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1532 AssignStaticWritePropertiesTo(*f1ts);
1533 if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfNodes())
1534 f1ts->setFieldNoProfileSBT(f2);
1537 part->setName(f1ts->createNewNameOfPfl().c_str());
1538 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1540 f1ts->write(fileName,0);
1546 void MEDLoader::WriteFieldDep(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1548 WriteField(fileName,f,writeFromScratch);
1551 void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f)
1554 throw INTERP_KERNEL::Exception("MEDLoader::WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1555 f->checkCoherency();
1556 int status=MEDLoaderBase::getStatusOfFile(fileName);
1557 if(status!=MEDLoaderBase::EXIST_RW)
1559 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1560 throw INTERP_KERNEL::Exception(oss.str().c_str());
1562 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1563 AssignStaticWritePropertiesTo(*f1ts);
1564 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1567 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
1568 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1569 f2->renumberCells(o2n->begin(),false);
1570 f1ts->setFieldNoProfileSBT(f2);
1573 f1ts->setFieldNoProfileSBT(f);
1574 f1ts->write(fileName,0);