1 // Copyright (C) 2007-2014 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) throw(INTERP_KERNEL::Exception);
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) throw(INTERP_KERNEL::Exception)
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())
597 std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
599 CheckFileForRead(fileName);
600 std::vector<ParaMEDMEM::TypeOfField> ret;
601 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
602 med_int nbFields=MEDnField(fid);
604 med_field_type typcha;
605 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
606 med_int numdt=0,numo=0;
608 char pflname[MED_NAME_SIZE+1]="";
609 char locname[MED_NAME_SIZE+1]="";
610 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
611 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
614 for(int i=0;i<nbFields;i++)
616 med_int ncomp=MEDfieldnComponent(fid,i+1);
617 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
618 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
619 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
621 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
622 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
623 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
624 if(curMeshName==meshName)
626 if(curFieldName==fieldName)
632 for(int ii=0;ii<nbPdt && !found;ii++)
634 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
635 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
636 pflname,&profilesize,locname,&nbi);
639 ret.push_back(ON_NODES);
645 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
649 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
650 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
651 pflname,&profilesize,locname,&nbi);
655 ret.push_back(ON_CELLS);
667 std::vector<std::string> MEDLoader::GetAllFieldNames(const std::string& fileName)
669 CheckFileForRead(fileName);
670 std::vector<std::string> ret;
671 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
672 med_int nbFields=MEDnField(fid);
673 med_field_type typcha;
674 for(int i=0;i<nbFields;i++)
676 med_int ncomp=MEDfieldnComponent(fid,i+1);
677 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
678 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
679 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
680 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
681 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
684 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
685 ret.push_back(std::string(nomcha));
690 std::vector<std::string> MEDLoader::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
692 CheckFileForRead(fileName);
693 std::vector<std::string> ret;
694 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
695 med_int nbFields=MEDnField(fid);
697 med_field_type typcha;
698 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
699 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
701 for(int i=0;i<nbFields;i++)
703 med_int ncomp=MEDfieldnComponent(fid,i+1);
704 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
705 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
706 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
709 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
710 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
711 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
713 if(curMeshName==meshName)
714 ret.push_back(curFieldName);
721 std::vector<std::string> MEDLoader::GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName)
723 CheckFileForRead(fileName);
727 return GetCellFieldNamesOnMesh(fileName,meshName);
729 return GetNodeFieldNamesOnMesh(fileName,meshName);
731 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
735 std::vector<std::string> MEDLoader::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
737 CheckFileForRead(fileName);
738 std::vector<std::string> ret;
739 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
740 med_int nbFields=MEDnField(fid);
742 med_field_type typcha;
743 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
744 med_int numdt=0,numo=0;
746 char pflname[MED_NAME_SIZE+1]="";
747 char locname[MED_NAME_SIZE+1]="";
748 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
749 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
750 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
754 for(int i=0;i<nbFields;i++)
756 med_int ncomp=MEDfieldnComponent(fid,i+1);
757 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
758 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
759 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
760 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
761 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
763 if(curMeshName==meshName)
766 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
770 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
771 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
772 pflname,&profilesize,locname,&nbi);
776 ret.push_back(curFieldName);
785 std::vector<std::string> MEDLoader::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
787 CheckFileForRead(fileName);
788 std::vector<std::string> ret;
789 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
790 med_int nbFields=MEDnField(fid);
791 char pflname[MED_NAME_SIZE+1]="";
792 char locname[MED_NAME_SIZE+1]="";
794 med_field_type typcha;
795 med_int numdt=0,numo=0;
797 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
798 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
799 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
802 for(int i=0;i<nbFields;i++)
804 med_int ncomp=MEDfieldnComponent(fid,i+1);
805 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
806 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
808 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
809 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
810 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
814 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
815 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
816 pflname,&profilesize,locname,&nbi);
817 if(curMeshName==meshName && nbOfVal>0)
819 ret.push_back(curFieldName);
826 std::vector< std::pair< std::pair<int,int>, double> > MEDLoader::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
828 CheckFileForRead(fileName);
829 std::vector< std::pair< std::pair<int,int>, double > > ret;
830 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
831 med_int nbFields=MEDnField(fid);
833 med_field_type typcha;
834 med_int numdt=0,numo=0;
836 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
837 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
838 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
841 std::ostringstream oss; oss << "MEDLoader::GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
842 for(int i=0;i<nbFields;i++)
844 med_int ncomp=MEDfieldnComponent(fid,i+1);
845 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
846 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
848 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
849 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
850 if(curFieldName==fieldName)
852 for(int k=0;k<nbPdt;k++)
854 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
855 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
861 oss << "\"" << curFieldName << "\"";
862 if(i!=nbFields-1) oss << ", ";
866 throw INTERP_KERNEL::Exception(oss.str().c_str());
869 double MEDLoader::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
871 CheckFileForRead(fileName);
872 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
873 med_int nbFields=MEDnField(fid);
875 med_field_type typcha;
876 med_int numdt=0,numo=0;
879 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
880 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
881 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
885 double ret=std::numeric_limits<double>::max();
886 for(int i=0;i<nbFields && !found;i++)
888 med_int ncomp=MEDfieldnComponent(fid,i+1);
889 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
890 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
892 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt);
893 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
894 if(curFieldName==fieldName)
897 for(int k=0;k<nbPdt;k++)
899 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
900 if(numdt==iteration && numo==order)
908 if(!found || !found2)
910 std::ostringstream oss;
911 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
912 throw INTERP_KERNEL::Exception(oss.str().c_str());
917 std::vector< std::pair<int,int> > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
919 CheckFileForRead(fileName);
923 return GetCellFieldIterations(fileName,meshName,fieldName);
925 return GetNodeFieldIterations(fileName,meshName,fieldName);
927 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
931 std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
933 CheckFileForRead(fileName);
934 std::string meshNameCpp(meshName);
935 std::vector< std::pair<int,int> > ret;
936 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
937 med_int nbFields=MEDnField(fid);
939 med_field_type typcha;
940 med_int numdt=0,numo=0;
942 char pflname[MED_NAME_SIZE+1]="";
943 char locname[MED_NAME_SIZE+1]="";
944 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
945 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
946 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
949 std::ostringstream oss; oss << "MEDLoader::GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
950 std::set<std::string> s2;
951 for(int i=0;i<nbFields;i++)
953 med_int ncomp=MEDfieldnComponent(fid,i+1);
954 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
955 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
957 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
958 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
959 if(curFieldName==fieldName)
962 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
964 for(int k=0;k<nbPdt;k++)
967 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
968 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
969 pflname,&profilesize,locname,&nbi);
970 std::string maa_ass_cpp(maa_ass);
973 if(meshNameCpp==maa_ass_cpp)
976 ret.push_back(std::make_pair(numdt,numo));
979 s2.insert(maa_ass_cpp);
986 oss << "\"" << curFieldName << "\"";
987 if(i!=nbFields-1) oss << ", ";
994 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
995 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
998 throw INTERP_KERNEL::Exception(oss.str().c_str());
1003 std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
1005 CheckFileForRead(fileName);
1006 std::string meshNameCpp(meshName);
1007 std::vector< std::pair<int,int> > ret;
1008 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
1009 med_int nbFields=MEDnField(fid);
1011 med_field_type typcha;
1012 med_int numdt=0,numo=0;
1014 char pflname[MED_NAME_SIZE+1]="";
1015 char locname[MED_NAME_SIZE+1]="";
1016 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1017 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
1018 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1021 std::ostringstream oss; oss << "MEDLoader::GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
1022 std::set<std::string> s2;
1023 for(int i=0;i<nbFields;i++)
1025 med_int ncomp=MEDfieldnComponent(fid,i+1);
1026 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
1027 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1029 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
1030 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1031 if(curFieldName==fieldName)
1033 for(int k=0;k<nbPdt;k++)
1035 int profilesize,nbi;
1036 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
1037 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1038 pflname,&profilesize,locname,&nbi);
1039 std::string maa_ass_cpp(maa_ass);
1042 if(meshNameCpp==maa_ass_cpp)
1043 { ret.push_back(std::make_pair(numdt,numo)); }
1045 s2.insert(maa_ass_cpp);
1051 oss << "\"" << curFieldName << "\"";
1052 if(i!=nbFields-1) oss << ", ";
1059 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1060 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1063 throw INTERP_KERNEL::Exception(oss.str().c_str());
1068 ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1070 CheckFileForRead(fileName);
1071 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1072 MEDFileMesh *mmPtr(mm);
1073 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1075 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1076 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1079 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1080 return const_cast<MEDCouplingCMesh *>(ret);
1082 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1085 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1086 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1088 std::ostringstream oss; oss << "MEDLoader::ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1089 throw INTERP_KERNEL::Exception(oss.str().c_str());
1092 ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1094 CheckFileForRead(fileName);
1095 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1096 MEDFileMesh *mmPtr(mm);
1097 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1099 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1100 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1103 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1104 return const_cast<MEDCouplingCMesh *>(ret);
1106 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1109 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1110 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1112 std::ostringstream oss; oss << "MEDLoader::ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1113 throw INTERP_KERNEL::Exception(oss.str().c_str());
1116 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
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::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1125 throw INTERP_KERNEL::Exception(oss.str().c_str());
1127 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1130 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1132 CheckFileForRead(fileName);
1133 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1134 MEDFileMesh *mmPtr(mm);
1135 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1138 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : 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->getMeshAtLevel(meshDimRelToMax,true);
1144 int MEDLoader::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1146 CheckFileForRead(fileName);
1147 std::vector<int> poss;
1148 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1151 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1153 CheckFileForRead(fileName);
1154 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1155 MEDFileMesh *mmPtr(mm);
1156 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1159 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1160 throw INTERP_KERNEL::Exception(oss.str().c_str());
1162 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1165 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1167 CheckFileForRead(fileName);
1168 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1169 MEDFileMesh *mmPtr(mm);
1170 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1173 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1174 throw INTERP_KERNEL::Exception(oss.str().c_str());
1176 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1179 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)
1181 CheckFileForRead(fileName);
1185 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1187 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1189 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1191 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1193 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1197 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsOnSameMesh(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1198 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1201 return std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>();
1202 CheckFileForRead(fileName);
1203 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> ret(its.size());
1204 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> > retSafe(its.size());
1207 //Retrieving mesh of rank 0 and field on rank 0 too.
1208 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1209 MEDFileMesh *mmPtr(mm);
1210 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1212 throw INTERP_KERNEL::Exception("MEDLoader::ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1213 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1214 const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1215 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m2(m->clone(true));
1217 m2->renumberCells(o2n->begin(),true);
1219 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1221 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1222 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1224 retElt->renumberCells(o2n->begin(),true);
1225 retElt->setMesh(m2);
1229 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1230 ret[i]=retSafe[i].retn();
1234 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1235 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1237 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1240 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1241 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1243 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1246 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1247 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1249 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1252 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1253 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1255 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1258 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1260 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1261 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1262 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1263 MEDFileMesh *mPtr(mm);
1264 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1265 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_CELLS,m);
1268 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1270 ret->renumberCells(num->begin());
1275 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1277 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1278 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1279 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1280 MEDFileMesh *mPtr(mm);
1281 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_NODES,m);
1282 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1283 if(ff->getPflsReallyUsed().empty())
1287 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1289 ret->renumberCells(num->begin());
1294 DataArrayInt *pfl=0,*arr2=0;
1295 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl);
1296 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflSafe(pfl);
1297 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> mp=m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end());
1298 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mzip=static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2));
1299 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2Safe(arr2);
1300 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes());
1301 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflSorted(pflSafe->deepCpy()); pflSorted->sort(true);
1302 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1303 throw INTERP_KERNEL::Exception("MEDLoader::ReadFieldNode : not implemented yet !");
1304 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1306 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n2=pflSafe->checkAndPreparePermutation();
1307 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o2=o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples());
1308 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1317 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1319 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1320 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1321 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1322 MEDFileMesh *mPtr(mm);
1323 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1324 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m);
1327 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1329 ret->renumberCells(num->begin());
1334 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1336 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1337 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1338 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1339 MEDFileMesh *mPtr(mm);
1340 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1341 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m);
1344 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1346 ret->renumberCells(num->begin());
1351 void MEDLoader::WriteMesh(const std::string& fileName, const ParaMEDMEM::MEDCouplingMesh *mesh, bool writeFromScratch)
1354 throw INTERP_KERNEL::Exception("MEDLoader::WriteMesh : input mesh is null !");
1355 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1358 WriteUMesh(fileName,um,writeFromScratch);
1361 int mod=writeFromScratch?2:0;
1362 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1365 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
1366 AssignStaticWritePropertiesTo(*mmu);
1367 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1368 mmu->write(fileName,mod);
1371 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1374 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc(MEDFileCMesh::New());
1375 AssignStaticWritePropertiesTo(*mmc);
1376 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1377 mmc->write(fileName,mod);
1380 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1383 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1384 AssignStaticWritePropertiesTo(*mmc);
1385 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1386 mmc->write(fileName,mod);
1389 throw INTERP_KERNEL::Exception("MEDLoader::WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1392 void MEDLoader::WriteUMesh(const std::string& fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch)
1395 throw INTERP_KERNEL::Exception("MEDLoader::WriteUMesh : input mesh is null !");
1396 int mod=writeFromScratch?2:0;
1397 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
1398 AssignStaticWritePropertiesTo(*m);
1399 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCpy()));
1400 m->setMeshAtLevel(0,mcpy,true);
1401 m->write(fileName,mod);
1404 void MEDLoader::WriteUMeshDep(const std::string& fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch)
1406 MEDLoader::WriteUMesh(fileName,mesh,writeFromScratch);
1409 void MEDLoader::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1411 std::string meshName(meshNameC);
1412 if(meshName.empty())
1413 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 !");
1414 int status=MEDLoaderBase::getStatusOfFile(fileName);
1415 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1417 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1418 throw INTERP_KERNEL::Exception(oss.str().c_str());
1420 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
1421 AssignStaticWritePropertiesTo(*m);
1422 m->setGroupsFromScratch(0,meshes,true);
1423 m->setName(meshNameC);
1424 int mod=writeFromScratch?2:0;
1425 m->write(fileName,mod);
1428 void MEDLoader::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1430 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1433 void MEDLoader::WriteUMeshes(const std::string& fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1435 int mod=writeFromScratch?2:0;
1436 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
1437 AssignStaticWritePropertiesTo(*m);
1438 m->setMeshes(meshes,true);
1439 m->write(fileName,mod);
1442 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1444 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff(MEDFileField1TS::New());
1445 MEDLoader::AssignStaticWritePropertiesTo(*ff);
1446 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1447 const MEDCouplingMesh *m(f2->getMesh());
1448 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1449 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1450 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1451 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1452 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
1453 int mod=writeFromScratch?2:0;
1456 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
1457 MEDLoader::AssignStaticWritePropertiesTo(*mmu);
1458 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(um->getRenumArrForMEDFileFrmt());
1459 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1460 f2->renumberCells(o2n->begin(),false);
1461 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1462 mmu->setRenumFieldArr(0,n2o);
1463 ff->setFieldNoProfileSBT(f2);
1464 mmu->write(fileName,mod);
1468 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
1469 MEDLoader::AssignStaticWritePropertiesTo(*mmu);
1470 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1471 ff->setFieldNoProfileSBT(f2);
1472 mmu->write(fileName,mod);
1476 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc(MEDFileCMesh::New());
1477 MEDLoader::AssignStaticWritePropertiesTo(*mmc);
1478 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1479 ff->setFieldNoProfileSBT(f2);
1480 mmc->write(fileName,mod);
1484 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1485 MEDLoader::AssignStaticWritePropertiesTo(*mmc);
1486 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1487 ff->setFieldNoProfileSBT(f2);
1488 mmc->write(fileName,mod);
1491 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1492 ff->write(fileName,0);
1495 void MEDLoader::WriteField(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1498 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : input field is NULL !");
1499 f->checkCoherency();
1500 int status=MEDLoaderBase::getStatusOfFile(fileName);
1501 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1503 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1504 throw INTERP_KERNEL::Exception(oss.str().c_str());
1506 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1508 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
1512 std::vector<std::string> meshNames=GetMeshNames(fileName);
1514 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : trying to write a field with no mesh !");
1515 std::string fileNameCpp(f->getMesh()->getName());
1516 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1517 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
1520 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1521 AssignStaticWritePropertiesTo(*mm);
1522 const MEDFileMesh *mmPtr(mm);
1523 const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
1525 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : only umeshes are supported now !");
1526 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1527 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1529 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : only umesh in input field supported !");
1530 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1531 f2->renumberCells(o2n->begin(),false);
1532 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1533 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
1534 if(f2->getTypeOfField()!=ON_NODES)
1536 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1537 DataArrayInt *part=0;
1538 bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
1539 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> partSafe(part);
1542 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 !";
1543 throw INTERP_KERNEL::Exception(oss.str().c_str());
1545 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1546 AssignStaticWritePropertiesTo(*f1ts);
1547 if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfCells())
1548 f1ts->setFieldNoProfileSBT(f2);
1551 part->setName(f1ts->createNewNameOfPfl().c_str());
1552 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1554 f1ts->write(fileName,0);
1559 DataArrayInt *part=0;
1560 bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
1561 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> partSafe(part);
1564 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 !";
1565 throw INTERP_KERNEL::Exception(oss.str().c_str());
1567 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1568 AssignStaticWritePropertiesTo(*f1ts);
1569 if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfNodes())
1570 f1ts->setFieldNoProfileSBT(f2);
1573 part->setName(f1ts->createNewNameOfPfl().c_str());
1574 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1576 f1ts->write(fileName,0);
1582 void MEDLoader::WriteFieldDep(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1584 WriteField(fileName,f,writeFromScratch);
1587 void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f)
1590 throw INTERP_KERNEL::Exception("MEDLoader::WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1591 f->checkCoherency();
1592 int status=MEDLoaderBase::getStatusOfFile(fileName);
1593 if(status!=MEDLoaderBase::EXIST_RW)
1595 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1596 throw INTERP_KERNEL::Exception(oss.str().c_str());
1598 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1599 AssignStaticWritePropertiesTo(*f1ts);
1600 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1603 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
1604 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1605 f2->renumberCells(o2n->begin(),false);
1606 f1ts->setFieldNoProfileSBT(f2);
1609 f1ts->setFieldNoProfileSBT(f);
1610 f1ts->write(fileName,0);