1 // Copyright (C) 2007-2013 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.
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 char *fileName, const char *meshName, std::vector<int>& possibilities);
145 void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity);
146 void writeFieldWithoutReadingAndMappingOfMeshInFile(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch);
147 med_int getIdFromMeshName(med_idt fid, const char *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 'meshName' into the file '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 char *fileName, const char *meshName, std::vector<int>& possibilities)
163 possibilities.clear();
164 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,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 char *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 bool MEDLoader::HasXDR()
296 std::string MEDLoader::MEDFileVersionStr()
298 return std::string(MED_VERSION_STR);
301 void MEDLoader::MEDFileVersion(int& major, int& minor, int& release)
303 major=MED_NUM_MAJEUR;
304 minor=MED_NUM_MINEUR;
305 release=MED_NUM_RELEASE;
309 * 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.
311 void MEDLoader::SetEpsilonForNodeComp(double val)
313 _EPS_FOR_NODE_COMP=val;
317 * 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.
319 void MEDLoader::SetCompPolicyForCell(int val)
325 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
326 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
328 void MEDLoader::SetTooLongStrPolicy(int val)
334 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
335 * It returns, in this order :
336 * - 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...
337 * - the mesh dimension
338 * - the space dimension
339 * - the number of nodes
341 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > MEDLoader::GetUMeshGlobalInfo(const char *fileName, const char *meshName, int &meshDim, int& spaceDim, int& numberOfNodes)
343 CheckFileForRead(fileName);
344 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
346 char nommaa[MED_NAME_SIZE+1];
347 char maillage_description[MED_COMMENT_SIZE+1];
348 med_mesh_type type_maillage;
349 std::string trueMeshName;
350 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
351 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
352 med_sorting_type sortingType;
354 med_axis_type axisType;
355 int naxis=MEDmeshnAxis(fid,meshId);
356 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
357 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
358 MEDmeshInfo(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit);
359 if(type_maillage!=MED_UNSTRUCTURED_MESH)
361 std::ostringstream oss; oss << "MEDLoader::GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
362 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
363 throw INTERP_KERNEL::Exception(oss.str().c_str());
367 throw INTERP_KERNEL::Exception("MEDLoader::GetUMeshGlobalInfo : multisteps on mesh not managed !");
370 MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
372 std::vector<int> dims;
373 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
374 med_bool changement,transformation;
375 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
377 med_geometry_type curMedType=typmai[i];
378 int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
381 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
382 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
383 dims.push_back(mdimCell);
384 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
387 int maxLev=*std::max_element(dims.begin(),dims.end());
388 int lowLev=*std::min_element(dims.begin(),dims.end());
389 int nbOfLevels=maxLev-lowLev+1;
390 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
391 for(std::size_t i=0;i<dims.size();i++)
393 ret[maxLev-dims[i]].push_back(geoTypes[i]);
395 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
399 void MEDLoader::CheckFileForRead(const char *fileName)
401 MEDFileUtilities::CheckFileForRead(fileName);
404 std::vector<std::string> MEDLoader::GetMeshNames(const char *fileName)
406 CheckFileForRead(fileName);
407 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
408 std::vector<std::string> ret=MEDLoaderNS::getMeshNamesFid(fid);
412 std::vector< std::pair<std::string,std::string> > MEDLoader::GetComponentsNamesOfField(const char *fileName, const char *fieldName)
414 CheckFileForRead(fileName);
415 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
416 med_int nbFields=MEDnField(fid);
417 std::vector<std::string> fields(nbFields);
418 med_field_type typcha;
419 for(int i=0;i<nbFields;i++)
421 med_int ncomp=MEDfieldnComponent(fid,i+1);
422 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
423 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
424 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
427 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
428 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
429 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
430 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
431 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
432 if(curFieldName==fieldName)
434 std::vector< std::pair<std::string,std::string> > ret(ncomp);
435 for(int j=0;j<ncomp;j++)
436 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
437 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
440 fields[i]=curFieldName;
442 std::ostringstream oss; oss << "MEDLoader::GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
443 oss << "Possible field names are : " << std::endl;
444 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
445 throw INTERP_KERNEL::Exception(oss.str().c_str());
448 std::vector<std::string> MEDLoader::GetMeshNamesOnField(const char *fileName, const char *fieldName)
450 CheckFileForRead(fileName);
451 std::vector<std::string> ret;
453 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
454 med_int nbFields=MEDnField(fid);
456 med_field_type typcha;
457 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
458 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
461 for(int i=0;i<nbFields;i++)
463 med_int ncomp=MEDfieldnComponent(fid,i+1);
464 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
465 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
467 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
468 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
469 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
470 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
471 if(curFieldName==fieldName)
472 ret.push_back(meshName);
477 std::vector<std::string> MEDLoader::GetMeshFamiliesNames(const char *fileName, const char *meshName)
479 CheckFileForRead(fileName);
480 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
481 med_int nfam=MEDnFamily(fid,meshName);
482 std::vector<std::string> ret(nfam);
483 char nomfam[MED_NAME_SIZE+1];
485 for(int i=0;i<nfam;i++)
487 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
488 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
489 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
490 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
491 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
492 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
493 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
494 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
501 std::vector<std::string> MEDLoader::GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName)
503 CheckFileForRead(fileName);
504 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
505 med_int nfam=MEDnFamily(fid,meshName);
506 std::vector<std::string> ret;
507 char nomfam[MED_NAME_SIZE+1];
509 for(int i=0;i<nfam;i++)
511 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
512 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
513 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
514 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
515 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
516 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
517 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
518 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
519 for(int j=0;j<ngro;j++)
521 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
529 std::vector<std::string> MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName)
531 CheckFileForRead(fileName);
532 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
533 med_int nfam=MEDnFamily(fid,meshName);
534 std::vector<std::string> ret;
535 char nomfam[MED_NAME_SIZE+1];
538 for(int i=0;i<nfam && !found;i++)
540 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
541 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
542 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
543 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
544 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
545 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
546 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
547 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
548 found=(cur==famName);
550 for(int j=0;j<ngro;j++)
552 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
558 std::ostringstream oss;
559 oss << "MEDLoader::GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
560 throw INTERP_KERNEL::Exception(oss.str().c_str());
566 std::vector<std::string> MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName)
568 CheckFileForRead(fileName);
569 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
570 med_int nfam=MEDnFamily(fid,meshName);
571 std::vector<std::string> ret;
572 char nomfam[MED_NAME_SIZE+1];
574 for(int i=0;i<nfam;i++)
576 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
577 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
578 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
579 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
580 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
581 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
582 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
583 for(int j=0;j<ngro;j++)
585 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
586 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
592 std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const char *fileName, const char *meshName, const char *fieldName)
594 CheckFileForRead(fileName);
595 std::vector<ParaMEDMEM::TypeOfField> ret;
596 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
597 med_int nbFields=MEDnField(fid);
599 med_field_type typcha;
600 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
601 med_int numdt=0,numo=0;
603 char pflname[MED_NAME_SIZE+1]="";
604 char locname[MED_NAME_SIZE+1]="";
605 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
606 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
609 for(int i=0;i<nbFields;i++)
611 med_int ncomp=MEDfieldnComponent(fid,i+1);
612 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
613 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
614 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
616 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
617 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
618 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
619 if(curMeshName==meshName)
621 if(curFieldName==fieldName)
627 for(int ii=0;ii<nbPdt && !found;ii++)
629 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
630 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
631 pflname,&profilesize,locname,&nbi);
634 ret.push_back(ON_NODES);
640 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
644 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
645 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
646 pflname,&profilesize,locname,&nbi);
650 ret.push_back(ON_CELLS);
662 std::vector<std::string> MEDLoader::GetAllFieldNames(const char *fileName)
664 CheckFileForRead(fileName);
665 std::vector<std::string> ret;
666 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
667 med_int nbFields=MEDnField(fid);
668 med_field_type typcha;
669 for(int i=0;i<nbFields;i++)
671 med_int ncomp=MEDfieldnComponent(fid,i+1);
672 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
673 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
674 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
675 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
676 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
679 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
680 ret.push_back(std::string(nomcha));
685 std::vector<std::string> MEDLoader::GetAllFieldNamesOnMesh(const char *fileName, const char *meshName)
687 CheckFileForRead(fileName);
688 std::vector<std::string> ret;
689 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
690 med_int nbFields=MEDnField(fid);
692 med_field_type typcha;
693 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
694 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
696 for(int i=0;i<nbFields;i++)
698 med_int ncomp=MEDfieldnComponent(fid,i+1);
699 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
700 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
701 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
704 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
705 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
706 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
708 if(curMeshName==meshName)
709 ret.push_back(curFieldName);
716 std::vector<std::string> MEDLoader::GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName)
718 CheckFileForRead(fileName);
722 return GetCellFieldNamesOnMesh(fileName,meshName);
724 return GetNodeFieldNamesOnMesh(fileName,meshName);
726 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
730 std::vector<std::string> MEDLoader::GetCellFieldNamesOnMesh(const char *fileName, const char *meshName)
732 CheckFileForRead(fileName);
733 std::vector<std::string> ret;
734 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
735 med_int nbFields=MEDnField(fid);
737 med_field_type typcha;
738 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
739 med_int numdt=0,numo=0;
741 char pflname[MED_NAME_SIZE+1]="";
742 char locname[MED_NAME_SIZE+1]="";
743 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
744 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
745 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
749 for(int i=0;i<nbFields;i++)
751 med_int ncomp=MEDfieldnComponent(fid,i+1);
752 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
753 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
754 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
755 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
756 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
758 if(curMeshName==meshName)
761 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
765 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
766 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
767 pflname,&profilesize,locname,&nbi);
771 ret.push_back(curFieldName);
780 std::vector<std::string> MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName)
782 CheckFileForRead(fileName);
783 std::vector<std::string> ret;
784 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
785 med_int nbFields=MEDnField(fid);
786 char pflname[MED_NAME_SIZE+1]="";
787 char locname[MED_NAME_SIZE+1]="";
789 med_field_type typcha;
790 med_int numdt=0,numo=0;
792 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
793 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
794 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
797 for(int i=0;i<nbFields;i++)
799 med_int ncomp=MEDfieldnComponent(fid,i+1);
800 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
801 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
803 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
804 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
805 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
809 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
810 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
811 pflname,&profilesize,locname,&nbi);
812 if(curMeshName==meshName && nbOfVal>0)
814 ret.push_back(curFieldName);
821 std::vector< std::pair< std::pair<int,int>, double> > MEDLoader::GetAllFieldIterations(const char *fileName, const char *fieldName)
823 CheckFileForRead(fileName);
824 std::vector< std::pair< std::pair<int,int>, double > > ret;
825 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
826 med_int nbFields=MEDnField(fid);
828 med_field_type typcha;
829 med_int numdt=0,numo=0;
831 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
832 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
833 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
836 std::ostringstream oss; oss << "MEDLoader::GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
837 for(int i=0;i<nbFields;i++)
839 med_int ncomp=MEDfieldnComponent(fid,i+1);
840 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
841 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
843 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
844 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
845 if(curFieldName==fieldName)
847 for(int k=0;k<nbPdt;k++)
849 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
850 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
856 oss << "\"" << curFieldName << "\"";
857 if(i!=nbFields-1) oss << ", ";
861 throw INTERP_KERNEL::Exception(oss.str().c_str());
864 double MEDLoader::GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order)
866 CheckFileForRead(fileName);
867 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
868 med_int nbFields=MEDnField(fid);
870 med_field_type typcha;
871 med_int numdt=0,numo=0;
874 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
875 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
876 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
880 double ret=std::numeric_limits<double>::max();
881 for(int i=0;i<nbFields && !found;i++)
883 med_int ncomp=MEDfieldnComponent(fid,i+1);
884 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
885 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
887 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt);
888 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
889 if(curFieldName==fieldName)
892 for(int k=0;k<nbPdt;k++)
894 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
895 if(numdt==iteration && numo==order)
903 if(!found || !found2)
905 std::ostringstream oss;
906 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
907 throw INTERP_KERNEL::Exception(oss.str().c_str());
912 std::vector< std::pair<int,int> > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName)
914 CheckFileForRead(fileName);
918 return GetCellFieldIterations(fileName,meshName,fieldName);
920 return GetNodeFieldIterations(fileName,meshName,fieldName);
922 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
926 std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName)
928 CheckFileForRead(fileName);
929 std::string meshNameCpp(meshName);
930 std::vector< std::pair<int,int> > ret;
931 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
932 med_int nbFields=MEDnField(fid);
934 med_field_type typcha;
935 med_int numdt=0,numo=0;
937 char pflname[MED_NAME_SIZE+1]="";
938 char locname[MED_NAME_SIZE+1]="";
939 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
940 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
941 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
944 std::ostringstream oss; oss << "MEDLoader::GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
945 std::set<std::string> s2;
946 for(int i=0;i<nbFields;i++)
948 med_int ncomp=MEDfieldnComponent(fid,i+1);
949 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
950 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
952 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
953 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
954 if(curFieldName==fieldName)
957 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
959 for(int k=0;k<nbPdt;k++)
962 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
963 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
964 pflname,&profilesize,locname,&nbi);
965 std::string maa_ass_cpp(maa_ass);
968 if(meshNameCpp==maa_ass_cpp)
971 ret.push_back(std::make_pair(numdt,numo));
974 s2.insert(maa_ass_cpp);
981 oss << "\"" << curFieldName << "\"";
982 if(i!=nbFields-1) oss << ", ";
989 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
990 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
993 throw INTERP_KERNEL::Exception(oss.str().c_str());
998 std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName)
1000 CheckFileForRead(fileName);
1001 std::string meshNameCpp(meshName);
1002 std::vector< std::pair<int,int> > ret;
1003 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1004 med_int nbFields=MEDnField(fid);
1006 med_field_type typcha;
1007 med_int numdt=0,numo=0;
1009 char pflname[MED_NAME_SIZE+1]="";
1010 char locname[MED_NAME_SIZE+1]="";
1011 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1012 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
1013 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1016 std::ostringstream oss; oss << "MEDLoader::GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
1017 std::set<std::string> s2;
1018 for(int i=0;i<nbFields;i++)
1020 med_int ncomp=MEDfieldnComponent(fid,i+1);
1021 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
1022 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1024 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
1025 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1026 if(curFieldName==fieldName)
1028 for(int k=0;k<nbPdt;k++)
1030 int profilesize,nbi;
1031 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
1032 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1033 pflname,&profilesize,locname,&nbi);
1034 std::string maa_ass_cpp(maa_ass);
1037 if(meshNameCpp==maa_ass_cpp)
1038 { ret.push_back(std::make_pair(numdt,numo)); }
1040 s2.insert(maa_ass_cpp);
1046 oss << "\"" << curFieldName << "\"";
1047 if(i!=nbFields-1) oss << ", ";
1054 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1055 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1058 throw INTERP_KERNEL::Exception(oss.str().c_str());
1063 ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax)
1065 CheckFileForRead(fileName);
1066 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1067 MEDFileMesh *mmPtr(mm);
1068 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1070 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1071 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1074 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1075 return const_cast<MEDCouplingCMesh *>(ret);
1077 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1080 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1081 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1083 std::ostringstream oss; oss << "MEDLoader::ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1084 throw INTERP_KERNEL::Exception(oss.str().c_str());
1087 ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const char *fileName, int meshDimRelToMax)
1089 CheckFileForRead(fileName);
1090 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName);
1091 MEDFileMesh *mmPtr(mm);
1092 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1094 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1095 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1098 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1099 return const_cast<MEDCouplingCMesh *>(ret);
1101 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1104 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1105 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1107 std::ostringstream oss; oss << "MEDLoader::ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1108 throw INTERP_KERNEL::Exception(oss.str().c_str());
1111 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax)
1113 CheckFileForRead(fileName);
1114 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1115 MEDFileMesh *mmPtr(mm);
1116 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1119 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1120 throw INTERP_KERNEL::Exception(oss.str().c_str());
1122 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1125 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, int meshDimRelToMax)
1127 CheckFileForRead(fileName);
1128 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName);
1129 MEDFileMesh *mmPtr(mm);
1130 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1133 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1134 throw INTERP_KERNEL::Exception(oss.str().c_str());
1136 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1139 int MEDLoader::ReadUMeshDimFromFile(const char *fileName, const char *meshName)
1141 CheckFileForRead(fileName);
1142 std::vector<int> poss;
1143 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1146 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1148 CheckFileForRead(fileName);
1149 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1150 MEDFileMesh *mmPtr(mm);
1151 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1154 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1155 throw INTERP_KERNEL::Exception(oss.str().c_str());
1157 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1160 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1162 CheckFileForRead(fileName);
1163 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1164 MEDFileMesh *mmPtr(mm);
1165 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1168 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1169 throw INTERP_KERNEL::Exception(oss.str().c_str());
1171 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1174 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadField(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order)
1176 CheckFileForRead(fileName);
1180 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1182 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1184 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1186 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1188 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1192 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsOnSameMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
1193 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1196 return std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>();
1197 CheckFileForRead(fileName);
1198 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> ret(its.size());
1199 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> > retSafe(its.size());
1202 //Retrieving mesh of rank 0 and field on rank 0 too.
1203 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1204 MEDFileMesh *mmPtr(mm);
1205 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1207 throw INTERP_KERNEL::Exception("MEDLoader::ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1208 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1209 const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1210 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m2(m->clone(true));
1212 m2->renumberCells(o2n->begin(),true);
1214 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1216 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1217 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1219 retElt->renumberCells(o2n->begin(),true);
1220 retElt->setMesh(m2);
1224 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1225 ret[i]=retSafe[i].retn();
1229 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsCellOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
1230 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1232 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1235 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsNodeOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
1236 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1238 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1241 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
1242 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1244 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1247 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussNEOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
1248 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
1250 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1253 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order)
1255 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1256 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1257 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1258 MEDFileMesh *mPtr(mm);
1259 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1260 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_CELLS,m);
1263 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1265 ret->renumberCells(num->begin());
1270 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order)
1272 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1273 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1274 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1275 MEDFileMesh *mPtr(mm);
1276 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_NODES,m);
1277 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1278 if(ff->getPflsReallyUsed().empty())
1282 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1284 ret->renumberCells(num->begin());
1289 DataArrayInt *pfl=0,*arr2=0;
1290 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl);
1291 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflSafe(pfl);
1292 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> mp=m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end());
1293 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mzip=static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2));
1294 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2Safe(arr2);
1295 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes());
1296 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflSorted(pflSafe->deepCpy()); pflSorted->sort(true);
1297 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1298 throw INTERP_KERNEL::Exception("MEDLoader::ReadFieldNode : not implemented yet !");
1299 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1301 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n2=pflSafe->checkAndPreparePermutation();
1302 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o2=o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples());
1303 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1312 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order)
1314 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1315 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1316 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1317 MEDFileMesh *mPtr(mm);
1318 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1319 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m);
1322 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1324 ret->renumberCells(num->begin());
1329 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order)
1331 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1332 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1333 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1334 MEDFileMesh *mPtr(mm);
1335 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1336 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m);
1339 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1341 ret->renumberCells(num->begin());
1346 void MEDLoader::WriteMesh(const char *fileName, const ParaMEDMEM::MEDCouplingMesh *mesh, bool writeFromScratch)
1349 throw INTERP_KERNEL::Exception("MEDLoader::WriteMesh : input mesh is null !");
1350 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1353 WriteUMesh(fileName,um,writeFromScratch);
1356 int mod=writeFromScratch?2:0;
1357 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1360 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu=MEDFileUMesh::New();
1361 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1362 mmu->write(fileName,mod);
1365 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1368 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc=MEDFileCMesh::New();
1369 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1370 mmc->write(fileName,mod);
1373 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1376 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc=MEDFileCurveLinearMesh::New();
1377 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1378 mmc->write(fileName,mod);
1381 throw INTERP_KERNEL::Exception("MEDLoader::WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1384 void MEDLoader::WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch)
1387 throw INTERP_KERNEL::Exception("MEDLoader::WriteUMesh : input mesh is null !");
1388 int mod=writeFromScratch?2:0;
1389 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m=MEDFileUMesh::New();
1390 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCpy()));
1391 m->setMeshAtLevel(0,mcpy,true);
1392 m->write(fileName,mod);
1395 void MEDLoader::WriteUMeshDep(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch)
1397 MEDLoader::WriteUMesh(fileName,mesh,writeFromScratch);
1400 void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1402 std::string meshName(meshNameC);
1403 if(meshName.empty())
1404 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 !");
1405 int status=MEDLoaderBase::getStatusOfFile(fileName);
1406 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1408 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1409 throw INTERP_KERNEL::Exception(oss.str().c_str());
1411 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m=MEDFileUMesh::New();
1412 m->setGroupsFromScratch(0,meshes,true);
1413 m->setName(meshNameC);
1414 int mod=writeFromScratch?2:0;
1415 m->write(fileName,mod);
1418 void MEDLoader::WriteUMeshesPartitionDep(const char *fileName, const char *meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1420 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1423 void MEDLoader::WriteUMeshes(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1425 int mod=writeFromScratch?2:0;
1426 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m=MEDFileUMesh::New();
1427 m->setMeshes(meshes,true);
1428 m->write(fileName,mod);
1431 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1433 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New();
1434 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1435 const MEDCouplingMesh *m(f2->getMesh());
1436 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1437 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1438 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1439 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1440 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
1441 int mod=writeFromScratch?2:0;
1444 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu=MEDFileUMesh::New();
1445 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=um->getRenumArrForMEDFileFrmt();
1446 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o=o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples());
1447 f2->renumberCells(o2n->begin(),false);
1448 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1449 mmu->setRenumFieldArr(0,n2o);
1450 ff->setFieldNoProfileSBT(f2);
1451 mmu->write(fileName,mod);
1455 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu=MEDFileUMesh::New();
1456 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1457 ff->setFieldNoProfileSBT(f2);
1458 mmu->write(fileName,mod);
1462 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc=MEDFileCMesh::New();
1463 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1464 ff->setFieldNoProfileSBT(f2);
1465 mmc->write(fileName,mod);
1469 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc=MEDFileCurveLinearMesh::New();
1470 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1471 ff->setFieldNoProfileSBT(f2);
1472 mmc->write(fileName,mod);
1475 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1476 ff->write(fileName,0);
1479 void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1482 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : input field is NULL !");
1483 f->checkCoherency();
1484 int status=MEDLoaderBase::getStatusOfFile(fileName);
1485 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1487 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1488 throw INTERP_KERNEL::Exception(oss.str().c_str());
1490 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1492 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
1496 std::vector<std::string> meshNames=GetMeshNames(fileName);
1498 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : trying to write a field with no mesh !");
1499 std::string fileNameCpp(f->getMesh()->getName());
1500 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1501 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
1504 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,f->getMesh()->getName().c_str());
1505 const MEDFileMesh *mmPtr(mm);
1506 const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
1508 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : only umeshes are supported now !");
1509 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1510 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1512 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : only umesh in input field supported !");
1513 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1514 f2->renumberCells(o2n->begin(),false);
1515 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1516 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
1517 if(f2->getTypeOfField()!=ON_NODES)
1519 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1520 DataArrayInt *part=0;
1521 bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
1522 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> partSafe(part);
1525 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 !";
1526 throw INTERP_KERNEL::Exception(oss.str().c_str());
1528 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts=MEDFileField1TS::New();
1529 if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfCells())
1530 f1ts->setFieldNoProfileSBT(f2);
1533 part->setName(f1ts->createNewNameOfPfl().c_str());
1534 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1536 f1ts->write(fileName,0);
1541 DataArrayInt *part=0;
1542 bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
1543 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> partSafe(part);
1546 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 !";
1547 throw INTERP_KERNEL::Exception(oss.str().c_str());
1549 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts=MEDFileField1TS::New();
1550 if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfNodes())
1551 f1ts->setFieldNoProfileSBT(f2);
1554 part->setName(f1ts->createNewNameOfPfl().c_str());
1555 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1557 f1ts->write(fileName,0);
1563 void MEDLoader::WriteFieldDep(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1565 WriteField(fileName,f,writeFromScratch);
1568 void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f)
1571 throw INTERP_KERNEL::Exception("MEDLoader::WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1572 f->checkCoherency();
1573 int status=MEDLoaderBase::getStatusOfFile(fileName);
1574 if(status!=MEDLoaderBase::EXIST_RW)
1576 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1577 throw INTERP_KERNEL::Exception(oss.str().c_str());
1579 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts=MEDFileField1TS::New();
1580 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh()));
1582 throw INTERP_KERNEL::Exception("MEDLoader::WriteFieldUsingAlreadyWrittenMesh : only umesh in input field supported !");
1583 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1584 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1585 f2->renumberCells(o2n->begin(),false);
1586 f1ts->setFieldNoProfileSBT(f2);
1587 f1ts->write(fileName,0);