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 "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"
32 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
34 #include "InterpKernelAutoPtr.hxx"
47 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
71 med_geometry_type typmainoeud[1] = { MED_NONE };
73 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
74 INTERP_KERNEL::NORM_SEG2,
75 INTERP_KERNEL::NORM_SEG3,
76 INTERP_KERNEL::NORM_SEG4,
77 INTERP_KERNEL::NORM_TRI3,
78 INTERP_KERNEL::NORM_QUAD4,
79 INTERP_KERNEL::NORM_TRI6,
80 INTERP_KERNEL::NORM_TRI7,
81 INTERP_KERNEL::NORM_QUAD8,
82 INTERP_KERNEL::NORM_QUAD9,
83 INTERP_KERNEL::NORM_TETRA4,
84 INTERP_KERNEL::NORM_PYRA5,
85 INTERP_KERNEL::NORM_PENTA6,
86 INTERP_KERNEL::NORM_HEXA8,
87 INTERP_KERNEL::NORM_HEXGP12,
88 INTERP_KERNEL::NORM_TETRA10,
89 INTERP_KERNEL::NORM_PYRA13,
90 INTERP_KERNEL::NORM_PENTA15,
91 INTERP_KERNEL::NORM_HEXA20,
92 INTERP_KERNEL::NORM_HEXA27,
93 INTERP_KERNEL::NORM_POLYGON,
94 INTERP_KERNEL::NORM_QPOLYG,
95 INTERP_KERNEL::NORM_POLYHED };
97 med_geometry_type typmai3[34] = { MED_POINT1,//0
133 double MEDLoader::_EPS_FOR_NODE_COMP=1.e-12;
135 int MEDLoader::_COMP_FOR_CELL=0;
137 int MEDLoader::_TOO_LONG_STR=0;
139 using namespace ParaMEDMEM;
143 namespace MEDLoaderNS
145 int readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities);
146 void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity);
147 void writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch);
148 med_int getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName);
149 std::vector<std::string> getMeshNamesFid(med_idt fid);
158 * This method returns a first quick overview of mesh with name \a meshName into the file \a fileName.
159 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
160 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
162 int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities)
164 possibilities.clear();
165 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
168 char nommaa[MED_NAME_SIZE+1];
169 char maillage_description[MED_COMMENT_SIZE+1];
170 med_mesh_type type_maillage;
172 std::string trueMeshName;
173 med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
174 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
175 med_sorting_type sortingType;
177 med_axis_type axisType;
178 int naxis(MEDmeshnAxis(fid,meshId));
179 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
180 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
181 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
185 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
189 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
191 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
193 med_geometry_type curMedType=typmai[i];
194 med_bool changement,transformation;
195 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
196 int curNbOfElemF(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));//limitation
198 med_entity_type whichEntity;
199 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
202 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
203 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
210 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
211 possibilities.push_back(*it-ret);
218 med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName)
222 std::vector<std::string> meshes=getMeshNamesFid(fid);
224 throw INTERP_KERNEL::Exception("No mesh in file");
225 trueMeshName=meshes[0];
228 std::string meshNameStr(meshName);
229 std::vector<std::string> meshes=getMeshNamesFid(fid);
231 throw INTERP_KERNEL::Exception("No mesh in file");
232 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
233 if(iter==meshes.end())
235 std::ostringstream os2;
236 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
237 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
238 throw INTERP_KERNEL::Exception(os2.str().c_str());
240 trueMeshName=meshName;
241 return iter-meshes.begin()+1;
244 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
246 med_mesh_type type_maillage;
247 char maillage_description[MED_COMMENT_SIZE+1];
248 char dtunit[MED_COMMENT_SIZE+1];
251 char nommaa[MED_NAME_SIZE+1];
252 med_axis_type axistype;
253 med_sorting_type stype;
254 med_int n=MEDnMesh(fid);
255 std::vector<std::string> ret(n);
258 int naxis(MEDmeshnAxis(fid,i+1));
259 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
260 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
262 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
263 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
270 * This methods allows to merger all entities and to considerate only cell types.
272 void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
274 if(nbOfElemCell>=nbOfElemFace)
276 whichEntity=MED_CELL;
277 nbOfElem=nbOfElemCell;
281 whichEntity=MED_CELL;
282 nbOfElem=nbOfElemFace;
288 void MEDLoader::AssignStaticWritePropertiesTo(ParaMEDMEM::MEDFileWritable& obj)
290 obj.setTooLongStrPolicy(_TOO_LONG_STR);
293 bool MEDLoader::HasXDR()
302 std::string MEDLoader::MEDFileVersionStr()
304 return std::string(MED_VERSION_STR);
307 void MEDLoader::MEDFileVersion(int& major, int& minor, int& release)
309 major=MED_NUM_MAJEUR;
310 minor=MED_NUM_MINEUR;
311 release=MED_NUM_RELEASE;
315 * 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.
317 void MEDLoader::SetEpsilonForNodeComp(double val)
319 _EPS_FOR_NODE_COMP=val;
323 * 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.
325 void MEDLoader::SetCompPolicyForCell(int val)
331 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
332 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
334 void MEDLoader::SetTooLongStrPolicy(int val)
340 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
341 * It returns, in this order :
342 * - 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...
343 * - the mesh dimension
344 * - the space dimension
345 * - the number of nodes
347 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)
349 CheckFileForRead(fileName);
350 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
352 char nommaa[MED_NAME_SIZE+1];
353 char maillage_description[MED_COMMENT_SIZE+1];
354 med_mesh_type type_maillage;
355 std::string trueMeshName;
356 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
357 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
358 med_sorting_type sortingType;
360 med_axis_type axisType;
361 int naxis(MEDmeshnAxis(fid,meshId));
362 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
363 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
364 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
365 if(type_maillage!=MED_UNSTRUCTURED_MESH)
367 std::ostringstream oss; oss << "MEDLoader::GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
368 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
369 throw INTERP_KERNEL::Exception(oss.str().c_str());
373 throw INTERP_KERNEL::Exception("MEDLoader::GetUMeshGlobalInfo : multisteps on mesh not managed !");
376 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
378 std::vector<int> dims;
379 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
380 med_bool changement,transformation;
381 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
383 med_geometry_type curMedType=typmai[i];
384 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
387 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
388 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
389 dims.push_back(mdimCell);
390 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
393 int maxLev=*std::max_element(dims.begin(),dims.end());
394 int lowLev=*std::min_element(dims.begin(),dims.end());
395 int nbOfLevels=maxLev-lowLev+1;
396 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
397 for(std::size_t i=0;i<dims.size();i++)
399 ret[maxLev-dims[i]].push_back(geoTypes[i]);
401 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
405 void MEDLoader::CheckFileForRead(const std::string& fileName)
407 MEDFileUtilities::CheckFileForRead(fileName);
410 std::vector<std::string> MEDLoader::GetMeshNames(const std::string& fileName)
412 CheckFileForRead(fileName);
413 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
414 std::vector<std::string> ret=MEDLoaderNS::getMeshNamesFid(fid);
418 std::vector< std::pair<std::string,std::string> > MEDLoader::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
420 CheckFileForRead(fileName);
421 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
422 med_int nbFields(MEDnField(fid));
423 std::vector<std::string> fields(nbFields);
424 med_field_type typcha;
425 for(int i=0;i<nbFields;i++)
427 med_int ncomp(MEDfieldnComponent(fid,i+1));
428 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
429 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
430 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
433 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
434 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
435 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
436 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
437 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
438 if(curFieldName==fieldName)
440 std::vector< std::pair<std::string,std::string> > ret(ncomp);
441 for(int j=0;j<ncomp;j++)
442 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
443 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
446 fields[i]=curFieldName;
448 std::ostringstream oss; oss << "MEDLoader::GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
449 oss << "Possible field names are : " << std::endl;
450 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
451 throw INTERP_KERNEL::Exception(oss.str().c_str());
454 std::vector<std::string> MEDLoader::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
456 CheckFileForRead(fileName);
457 std::vector<std::string> ret;
459 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
460 med_int nbFields=MEDnField(fid);
462 med_field_type typcha;
463 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
464 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
467 for(int i=0;i<nbFields;i++)
469 med_int ncomp(MEDfieldnComponent(fid,i+1));
470 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
471 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
473 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
474 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
475 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
476 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
477 if(curFieldName==fieldName)
478 ret.push_back(meshName);
483 std::vector<std::string> MEDLoader::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
485 CheckFileForRead(fileName);
486 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
487 med_int nfam=MEDnFamily(fid,meshName.c_str());
488 std::vector<std::string> ret(nfam);
489 char nomfam[MED_NAME_SIZE+1];
491 for(int i=0;i<nfam;i++)
493 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
494 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
495 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
496 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
497 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
498 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
499 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
500 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
507 std::vector<std::string> MEDLoader::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
509 CheckFileForRead(fileName);
510 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
511 med_int nfam=MEDnFamily(fid,meshName.c_str());
512 std::vector<std::string> ret;
513 char nomfam[MED_NAME_SIZE+1];
515 for(int i=0;i<nfam;i++)
517 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
518 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
519 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
520 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
521 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
522 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
523 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
524 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
525 for(int j=0;j<ngro;j++)
527 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
535 std::vector<std::string> MEDLoader::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
537 CheckFileForRead(fileName);
538 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
539 med_int nfam=MEDnFamily(fid,meshName.c_str());
540 std::vector<std::string> ret;
541 char nomfam[MED_NAME_SIZE+1];
544 for(int i=0;i<nfam && !found;i++)
546 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
547 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
548 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
549 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
550 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
551 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
552 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
553 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
554 found=(cur==famName);
556 for(int j=0;j<ngro;j++)
558 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
564 std::ostringstream oss;
565 oss << "MEDLoader::GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
566 throw INTERP_KERNEL::Exception(oss.str().c_str());
572 std::vector<std::string> MEDLoader::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
574 CheckFileForRead(fileName);
575 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
576 med_int nfam=MEDnFamily(fid,meshName.c_str());
577 std::vector<std::string> ret;
578 char nomfam[MED_NAME_SIZE+1];
580 for(int i=0;i<nfam;i++)
582 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
583 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
584 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
585 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
586 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
587 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
588 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
589 for(int j=0;j<ngro;j++)
591 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
592 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
599 std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
601 std::vector<ParaMEDMEM::TypeOfField> ret;
602 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> fs(MEDFileAnyTypeFieldMultiTS::New(fileName,fieldName,false));
603 if(fs->getMeshName()!=meshName)
605 std::ostringstream oss; oss << "MEDLoader::GetTypesOfField : The field \"" << fieldName << "\" in file \"" << fileName << "\" is not lying on mesh \"" << meshName << "\"";
606 oss << " The name of the mesh in file is \"" << fs->getMeshName() << "\"!";
607 throw INTERP_KERNEL::Exception(oss.str().c_str());
609 int nbTS(fs->getNumberOfTS());
612 for(int i=0;i<nbTS;i++)
614 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1ts(fs->getTimeStepAtPos(i));
615 std::vector<ParaMEDMEM::TypeOfField> tof(f1ts->getTypesOfFieldAvailable());
616 for(std::vector<ParaMEDMEM::TypeOfField>::const_iterator it=tof.begin();it!=tof.end();it++)
617 if(std::find(ret.begin(),ret.end(),*it)==ret.end())
620 // sort ret to put before ON_NODES then ON_CELLS then the remaining.
621 std::vector<ParaMEDMEM::TypeOfField> ret2;
622 if(std::find(ret.begin(),ret.end(),ON_NODES)!=ret.end())
623 ret2.push_back(ON_NODES);
624 if(std::find(ret.begin(),ret.end(),ON_CELLS)!=ret.end())
625 ret2.push_back(ON_CELLS);
626 for(std::vector<ParaMEDMEM::TypeOfField>::const_iterator it=ret.begin();it!=ret.end();it++)
627 if(*it!=ON_NODES && *it!=ON_CELLS)
632 std::vector<std::string> MEDLoader::GetAllFieldNames(const std::string& fileName)
634 CheckFileForRead(fileName);
635 std::vector<std::string> ret;
636 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
637 med_int nbFields=MEDnField(fid);
638 med_field_type typcha;
639 for(int i=0;i<nbFields;i++)
641 med_int ncomp(MEDfieldnComponent(fid,i+1));
642 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
643 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
644 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
645 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
646 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
649 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
650 ret.push_back(std::string(nomcha));
655 std::vector<std::string> MEDLoader::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
657 CheckFileForRead(fileName);
658 std::vector<std::string> ret;
659 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
660 med_int nbFields=MEDnField(fid);
662 med_field_type typcha;
663 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
664 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
666 for(int i=0;i<nbFields;i++)
668 med_int ncomp(MEDfieldnComponent(fid,i+1));
669 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
670 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
671 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
674 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
675 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
676 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
678 if(curMeshName==meshName)
679 ret.push_back(curFieldName);
686 std::vector<std::string> MEDLoader::GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName)
688 CheckFileForRead(fileName);
692 return GetCellFieldNamesOnMesh(fileName,meshName);
694 return GetNodeFieldNamesOnMesh(fileName,meshName);
696 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
700 std::vector<std::string> MEDLoader::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
702 CheckFileForRead(fileName);
703 std::vector<std::string> ret;
704 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
705 med_int nbFields=MEDnField(fid);
707 med_field_type typcha;
708 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
709 med_int numdt=0,numo=0;
711 char pflname[MED_NAME_SIZE+1]="";
712 char locname[MED_NAME_SIZE+1]="";
713 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
714 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
715 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
719 for(int i=0;i<nbFields;i++)
721 med_int ncomp(MEDfieldnComponent(fid,i+1));
722 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
723 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
724 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
725 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
726 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
728 if(curMeshName==meshName)
731 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
735 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
736 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
737 pflname,&profilesize,locname,&nbi));
741 ret.push_back(curFieldName);
750 std::vector<std::string> MEDLoader::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
752 CheckFileForRead(fileName);
753 std::vector<std::string> ret;
754 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
755 med_int nbFields=MEDnField(fid);
756 char pflname[MED_NAME_SIZE+1]="";
757 char locname[MED_NAME_SIZE+1]="";
759 med_field_type typcha;
760 med_int numdt=0,numo=0;
762 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
763 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
764 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
767 for(int i=0;i<nbFields;i++)
769 med_int ncomp(MEDfieldnComponent(fid,i+1));
770 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
771 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
773 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
774 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
775 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
779 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
780 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
781 pflname,&profilesize,locname,&nbi));
782 if(curMeshName==meshName && nbOfVal>0)
784 ret.push_back(curFieldName);
791 std::vector< std::pair< std::pair<int,int>, double> > MEDLoader::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
793 CheckFileForRead(fileName);
794 std::vector< std::pair< std::pair<int,int>, double > > ret;
795 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
796 med_int nbFields=MEDnField(fid);
798 med_field_type typcha;
799 med_int numdt=0,numo=0;
801 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
802 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
803 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
806 std::ostringstream oss; oss << "MEDLoader::GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
807 for(int i=0;i<nbFields;i++)
809 med_int ncomp(MEDfieldnComponent(fid,i+1));
810 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
811 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
813 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
814 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
815 if(curFieldName==fieldName)
817 for(int k=0;k<nbPdt;k++)
819 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
820 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
826 oss << "\"" << curFieldName << "\"";
827 if(i!=nbFields-1) oss << ", ";
831 throw INTERP_KERNEL::Exception(oss.str().c_str());
834 double MEDLoader::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
836 CheckFileForRead(fileName);
837 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
838 med_int nbFields=MEDnField(fid);
840 med_field_type typcha;
841 med_int numdt=0,numo=0;
844 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
845 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
846 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
850 double ret=std::numeric_limits<double>::max();
851 for(int i=0;i<nbFields && !found;i++)
853 med_int ncomp(MEDfieldnComponent(fid,i+1));
854 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
855 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
857 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt));
858 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
859 if(curFieldName==fieldName)
862 for(int k=0;k<nbPdt;k++)
864 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
865 if(numdt==iteration && numo==order)
873 if(!found || !found2)
875 std::ostringstream oss;
876 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
877 throw INTERP_KERNEL::Exception(oss.str().c_str());
882 std::vector< std::pair<int,int> > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
884 CheckFileForRead(fileName);
888 return GetCellFieldIterations(fileName,meshName,fieldName);
890 return GetNodeFieldIterations(fileName,meshName,fieldName);
892 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
896 std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
898 CheckFileForRead(fileName);
899 std::string meshNameCpp(meshName);
900 std::vector< std::pair<int,int> > ret;
901 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
902 med_int nbFields=MEDnField(fid);
904 med_field_type typcha;
905 med_int numdt=0,numo=0;
907 char pflname[MED_NAME_SIZE+1]="";
908 char locname[MED_NAME_SIZE+1]="";
909 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
910 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
911 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
914 std::ostringstream oss; oss << "MEDLoader::GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
915 std::set<std::string> s2;
916 for(int i=0;i<nbFields;i++)
918 med_int ncomp(MEDfieldnComponent(fid,i+1));
919 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
920 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
922 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
923 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
924 if(curFieldName==fieldName)
927 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
929 for(int k=0;k<nbPdt;k++)
932 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
933 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
934 pflname,&profilesize,locname,&nbi));
935 std::string maa_ass_cpp(maa_ass);
938 if(meshNameCpp==maa_ass_cpp)
941 ret.push_back(std::make_pair(numdt,numo));
944 s2.insert(maa_ass_cpp);
951 oss << "\"" << curFieldName << "\"";
952 if(i!=nbFields-1) oss << ", ";
959 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
960 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
963 throw INTERP_KERNEL::Exception(oss.str().c_str());
968 std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
970 CheckFileForRead(fileName);
971 std::string meshNameCpp(meshName);
972 std::vector< std::pair<int,int> > ret;
973 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
974 med_int nbFields=MEDnField(fid);
976 med_field_type typcha;
977 med_int numdt=0,numo=0;
979 char pflname[MED_NAME_SIZE+1]="";
980 char locname[MED_NAME_SIZE+1]="";
981 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
982 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
983 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
986 std::ostringstream oss; oss << "MEDLoader::GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
987 std::set<std::string> s2;
988 for(int i=0;i<nbFields;i++)
990 med_int ncomp(MEDfieldnComponent(fid,i+1));
991 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
992 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
994 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
995 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
996 if(curFieldName==fieldName)
998 for(int k=0;k<nbPdt;k++)
1000 int profilesize,nbi;
1001 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
1002 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1003 pflname,&profilesize,locname,&nbi));
1004 std::string maa_ass_cpp(maa_ass);
1007 if(meshNameCpp==maa_ass_cpp)
1008 { ret.push_back(std::make_pair(numdt,numo)); }
1010 s2.insert(maa_ass_cpp);
1016 oss << "\"" << curFieldName << "\"";
1017 if(i!=nbFields-1) oss << ", ";
1024 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1025 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1028 throw INTERP_KERNEL::Exception(oss.str().c_str());
1033 ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1035 CheckFileForRead(fileName);
1036 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1037 MEDFileMesh *mmPtr(mm);
1038 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1040 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1041 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1044 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1045 return const_cast<MEDCouplingCMesh *>(ret);
1047 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1050 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1051 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1053 std::ostringstream oss; oss << "MEDLoader::ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1054 throw INTERP_KERNEL::Exception(oss.str().c_str());
1057 ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1059 CheckFileForRead(fileName);
1060 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1061 MEDFileMesh *mmPtr(mm);
1062 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1064 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1065 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1068 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1069 return const_cast<MEDCouplingCMesh *>(ret);
1071 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1074 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1075 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1077 std::ostringstream oss; oss << "MEDLoader::ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1078 throw INTERP_KERNEL::Exception(oss.str().c_str());
1081 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1083 CheckFileForRead(fileName);
1084 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1085 MEDFileMesh *mmPtr(mm);
1086 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1089 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1090 throw INTERP_KERNEL::Exception(oss.str().c_str());
1092 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1095 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1097 CheckFileForRead(fileName);
1098 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1099 MEDFileMesh *mmPtr(mm);
1100 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1103 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1104 throw INTERP_KERNEL::Exception(oss.str().c_str());
1106 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1109 int MEDLoader::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1111 CheckFileForRead(fileName);
1112 std::vector<int> poss;
1113 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1116 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1118 CheckFileForRead(fileName);
1119 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1120 MEDFileMesh *mmPtr(mm);
1121 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1124 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1125 throw INTERP_KERNEL::Exception(oss.str().c_str());
1127 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1130 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1132 CheckFileForRead(fileName);
1133 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1134 MEDFileMesh *mmPtr(mm);
1135 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1138 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1139 throw INTERP_KERNEL::Exception(oss.str().c_str());
1141 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1144 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)
1146 CheckFileForRead(fileName);
1150 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1152 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1154 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1156 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1158 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1162 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsOnSameMesh(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1163 const std::vector<std::pair<int,int> >& its)
1166 return std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>();
1167 CheckFileForRead(fileName);
1168 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> ret(its.size());
1169 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> > retSafe(its.size());
1172 //Retrieving mesh of rank 0 and field on rank 0 too.
1173 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1174 MEDFileMesh *mmPtr(mm);
1175 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1177 throw INTERP_KERNEL::Exception("MEDLoader::ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1178 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1179 const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1180 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m2(m->clone(true));
1182 m2->renumberCells(o2n->begin(),true);
1184 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1186 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1187 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1189 retElt->renumberCells(o2n->begin(),true);
1190 retElt->setMesh(m2);
1194 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1195 ret[i]=retSafe[i].retn();
1199 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1200 const std::vector<std::pair<int,int> >& its)
1202 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1205 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1206 const std::vector<std::pair<int,int> >& its)
1208 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1211 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1212 const std::vector<std::pair<int,int> >& its)
1214 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1217 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1218 const std::vector<std::pair<int,int> >& its)
1220 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1223 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1225 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1226 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1227 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1228 MEDFileMesh *mPtr(mm);
1229 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1230 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_CELLS,m);
1233 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1235 ret->renumberCells(num->begin());
1240 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1242 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1243 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1244 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1245 MEDFileMesh *mPtr(mm);
1246 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_NODES,m);
1247 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1248 if(ff->getPflsReallyUsed().empty())
1252 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1254 ret->renumberCells(num->begin());
1259 DataArrayInt *pfl=0,*arr2=0;
1260 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl);
1261 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflSafe(pfl);
1262 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> mp=m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end());
1263 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mzip=static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2));
1264 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2Safe(arr2);
1265 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes());
1266 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflSorted(pflSafe->deepCpy()); pflSorted->sort(true);
1267 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1268 throw INTERP_KERNEL::Exception("MEDLoader::ReadFieldNode : not implemented yet !");
1269 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1271 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n2=pflSafe->checkAndPreparePermutation();
1272 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o2=o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples());
1273 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1282 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1284 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1285 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1286 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1287 MEDFileMesh *mPtr(mm);
1288 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1289 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m);
1292 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1294 ret->renumberCells(num->begin());
1299 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1301 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1302 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1303 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1304 MEDFileMesh *mPtr(mm);
1305 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1306 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m);
1309 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1311 ret->renumberCells(num->begin());
1316 void MEDLoader::WriteMesh(const std::string& fileName, const ParaMEDMEM::MEDCouplingMesh *mesh, bool writeFromScratch)
1319 throw INTERP_KERNEL::Exception("MEDLoader::WriteMesh : input mesh is null !");
1320 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1323 WriteUMesh(fileName,um,writeFromScratch);
1326 int mod=writeFromScratch?2:0;
1327 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1330 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
1331 AssignStaticWritePropertiesTo(*mmu);
1332 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1333 mmu->write(fileName,mod);
1336 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1339 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc(MEDFileCMesh::New());
1340 AssignStaticWritePropertiesTo(*mmc);
1341 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1342 mmc->write(fileName,mod);
1345 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1348 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1349 AssignStaticWritePropertiesTo(*mmc);
1350 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1351 mmc->write(fileName,mod);
1354 throw INTERP_KERNEL::Exception("MEDLoader::WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1357 void MEDLoader::WriteUMesh(const std::string& fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch)
1360 throw INTERP_KERNEL::Exception("MEDLoader::WriteUMesh : input mesh is null !");
1361 int mod=writeFromScratch?2:0;
1362 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
1363 AssignStaticWritePropertiesTo(*m);
1364 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCpy()));
1365 m->setMeshAtLevel(0,mcpy,true);
1366 m->write(fileName,mod);
1369 void MEDLoader::WriteUMeshDep(const std::string& fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch)
1371 MEDLoader::WriteUMesh(fileName,mesh,writeFromScratch);
1374 void MEDLoader::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1376 std::string meshName(meshNameC);
1377 if(meshName.empty())
1378 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 !");
1379 int status=MEDLoaderBase::getStatusOfFile(fileName);
1380 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1382 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1383 throw INTERP_KERNEL::Exception(oss.str().c_str());
1385 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
1386 AssignStaticWritePropertiesTo(*m);
1387 m->setGroupsFromScratch(0,meshes,true);
1388 m->setName(meshNameC);
1389 int mod=writeFromScratch?2:0;
1390 m->write(fileName,mod);
1393 void MEDLoader::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1395 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1398 void MEDLoader::WriteUMeshes(const std::string& fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1400 int mod=writeFromScratch?2:0;
1401 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
1402 AssignStaticWritePropertiesTo(*m);
1403 m->setMeshes(meshes,true);
1404 m->write(fileName,mod);
1407 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1409 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff(MEDFileField1TS::New());
1410 MEDLoader::AssignStaticWritePropertiesTo(*ff);
1411 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1412 const MEDCouplingMesh *m(f2->getMesh());
1413 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1414 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1415 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1416 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1417 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
1418 int mod=writeFromScratch?2:0;
1421 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
1422 MEDLoader::AssignStaticWritePropertiesTo(*mmu);
1423 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(um->getRenumArrForMEDFileFrmt());
1424 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1425 f2->renumberCells(o2n->begin(),false);
1426 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1427 mmu->setRenumFieldArr(0,n2o);
1428 ff->setFieldNoProfileSBT(f2);
1429 mmu->write(fileName,mod);
1433 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
1434 MEDLoader::AssignStaticWritePropertiesTo(*mmu);
1435 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1436 ff->setFieldNoProfileSBT(f2);
1437 mmu->write(fileName,mod);
1441 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc(MEDFileCMesh::New());
1442 MEDLoader::AssignStaticWritePropertiesTo(*mmc);
1443 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1444 ff->setFieldNoProfileSBT(f2);
1445 mmc->write(fileName,mod);
1449 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1450 MEDLoader::AssignStaticWritePropertiesTo(*mmc);
1451 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1452 ff->setFieldNoProfileSBT(f2);
1453 mmc->write(fileName,mod);
1456 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1457 ff->write(fileName,0);
1460 void MEDLoader::WriteField(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1463 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : input field is NULL !");
1464 f->checkCoherency();
1465 int status=MEDLoaderBase::getStatusOfFile(fileName);
1466 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1468 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1469 throw INTERP_KERNEL::Exception(oss.str().c_str());
1471 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1473 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
1477 std::vector<std::string> meshNames=GetMeshNames(fileName);
1479 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : trying to write a field with no mesh !");
1480 std::string fileNameCpp(f->getMesh()->getName());
1481 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1482 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
1485 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1486 AssignStaticWritePropertiesTo(*mm);
1487 const MEDFileMesh *mmPtr(mm);
1488 const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
1490 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : only umeshes are supported now !");
1491 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1492 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1494 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : only umesh in input field supported !");
1495 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1496 f2->renumberCells(o2n->begin(),false);
1497 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1498 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
1499 if(f2->getTypeOfField()!=ON_NODES)
1501 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1502 DataArrayInt *part=0;
1503 bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
1504 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> partSafe(part);
1507 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 !";
1508 throw INTERP_KERNEL::Exception(oss.str().c_str());
1510 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1511 AssignStaticWritePropertiesTo(*f1ts);
1512 if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfCells())
1513 f1ts->setFieldNoProfileSBT(f2);
1516 part->setName(f1ts->createNewNameOfPfl().c_str());
1517 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1519 f1ts->write(fileName,0);
1524 DataArrayInt *part=0;
1525 bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
1526 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> partSafe(part);
1529 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 !";
1530 throw INTERP_KERNEL::Exception(oss.str().c_str());
1532 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1533 AssignStaticWritePropertiesTo(*f1ts);
1534 if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfNodes())
1535 f1ts->setFieldNoProfileSBT(f2);
1538 part->setName(f1ts->createNewNameOfPfl().c_str());
1539 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1541 f1ts->write(fileName,0);
1547 void MEDLoader::WriteFieldDep(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1549 WriteField(fileName,f,writeFromScratch);
1552 void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f)
1555 throw INTERP_KERNEL::Exception("MEDLoader::WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1556 f->checkCoherency();
1557 int status=MEDLoaderBase::getStatusOfFile(fileName);
1558 if(status!=MEDLoaderBase::EXIST_RW)
1560 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1561 throw INTERP_KERNEL::Exception(oss.str().c_str());
1563 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1564 AssignStaticWritePropertiesTo(*f1ts);
1565 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1568 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
1569 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1570 f2->renumberCells(o2n->begin(),false);
1571 f1ts->setFieldNoProfileSBT(f2);
1574 f1ts->setFieldNoProfileSBT(f);
1575 f1ts->write(fileName,0);