1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDLoader.hxx"
22 #include "MEDLoaderBase.hxx"
23 #include "MEDFileUtilities.hxx"
24 #include "MEDFileSafeCaller.txx"
25 #include "MEDFileMesh.hxx"
26 #include "MEDFileField.hxx"
27 #include "CellModel.hxx"
28 #include "MEDCouplingUMesh.hxx"
29 #include "MEDCouplingMemArray.hxx"
30 #include "MEDCouplingFieldDouble.hxx"
31 #include "MEDCouplingGaussLocalization.hxx"
32 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
34 #include "InterpKernelAutoPtr.hxx"
49 * \brief Static class offering the "basic" API to read and write MED files/
51 * This class implements only static methods and offers the high level API to access MED files.
52 * Take a look at \ref medloader for more details.
56 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
80 med_geometry_type typmainoeud[1] = { MED_NONE };
82 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
83 INTERP_KERNEL::NORM_SEG2,
84 INTERP_KERNEL::NORM_SEG3,
85 INTERP_KERNEL::NORM_SEG4,
86 INTERP_KERNEL::NORM_TRI3,
87 INTERP_KERNEL::NORM_QUAD4,
88 INTERP_KERNEL::NORM_TRI6,
89 INTERP_KERNEL::NORM_TRI7,
90 INTERP_KERNEL::NORM_QUAD8,
91 INTERP_KERNEL::NORM_QUAD9,
92 INTERP_KERNEL::NORM_TETRA4,
93 INTERP_KERNEL::NORM_PYRA5,
94 INTERP_KERNEL::NORM_PENTA6,
95 INTERP_KERNEL::NORM_HEXA8,
96 INTERP_KERNEL::NORM_HEXGP12,
97 INTERP_KERNEL::NORM_TETRA10,
98 INTERP_KERNEL::NORM_PYRA13,
99 INTERP_KERNEL::NORM_PENTA15,
100 INTERP_KERNEL::NORM_HEXA20,
101 INTERP_KERNEL::NORM_HEXA27,
102 INTERP_KERNEL::NORM_POLYGON,
103 INTERP_KERNEL::NORM_QPOLYG,
104 INTERP_KERNEL::NORM_POLYHED };
106 med_geometry_type typmai3[34] = { MED_POINT1,//0
142 double MEDLoader::_EPS_FOR_NODE_COMP=1.e-12;
144 int MEDLoader::_COMP_FOR_CELL=0;
146 int MEDLoader::_TOO_LONG_STR=0;
148 using namespace ParaMEDMEM;
152 namespace MEDLoaderNS
154 int readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities);
155 void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity);
156 void writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch);
157 med_int getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName);
158 std::vector<std::string> getMeshNamesFid(med_idt fid);
167 * This method returns a first quick overview of mesh with name \a meshName into the file \a fileName.
168 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
169 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
171 int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities)
173 possibilities.clear();
174 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
177 char nommaa[MED_NAME_SIZE+1];
178 char maillage_description[MED_COMMENT_SIZE+1];
179 med_mesh_type type_maillage;
181 std::string trueMeshName;
182 med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
183 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
184 med_sorting_type sortingType;
186 med_axis_type axisType;
187 int naxis(MEDmeshnAxis(fid,meshId));
188 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
189 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
190 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
194 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
198 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
200 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
202 med_geometry_type curMedType=typmai[i];
203 med_bool changement,transformation;
204 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
205 int curNbOfElemF(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));//limitation
207 med_entity_type whichEntity;
208 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
211 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
212 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
219 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
220 possibilities.push_back(*it-ret);
227 med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName)
231 std::vector<std::string> meshes=getMeshNamesFid(fid);
233 throw INTERP_KERNEL::Exception("No mesh in file");
234 trueMeshName=meshes[0];
237 std::string meshNameStr(meshName);
238 std::vector<std::string> meshes=getMeshNamesFid(fid);
240 throw INTERP_KERNEL::Exception("No mesh in file");
241 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
242 if(iter==meshes.end())
244 std::ostringstream os2;
245 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
246 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
247 throw INTERP_KERNEL::Exception(os2.str().c_str());
249 trueMeshName=meshName;
250 return iter-meshes.begin()+1;
253 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
255 med_mesh_type type_maillage;
256 char maillage_description[MED_COMMENT_SIZE+1];
257 char dtunit[MED_COMMENT_SIZE+1];
260 char nommaa[MED_NAME_SIZE+1];
261 med_axis_type axistype;
262 med_sorting_type stype;
263 med_int n=MEDnMesh(fid);
264 std::vector<std::string> ret(n);
267 int naxis(MEDmeshnAxis(fid,i+1));
268 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
269 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
271 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
272 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
279 * This methods allows to merger all entities and to considerate only cell types.
281 void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
283 if(nbOfElemCell>=nbOfElemFace)
285 whichEntity=MED_CELL;
286 nbOfElem=nbOfElemCell;
290 whichEntity=MED_CELL;
291 nbOfElem=nbOfElemFace;
297 void MEDLoader::AssignStaticWritePropertiesTo(ParaMEDMEM::MEDFileWritable& obj)
299 obj.setTooLongStrPolicy(_TOO_LONG_STR);
302 bool MEDLoader::HasXDR()
311 std::string MEDLoader::MEDFileVersionStr()
313 return std::string(MED_VERSION_STR);
316 void MEDLoader::MEDFileVersion(int& major, int& minor, int& release)
318 major=MED_NUM_MAJEUR;
319 minor=MED_NUM_MINEUR;
320 release=MED_NUM_RELEASE;
324 * 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.
326 void MEDLoader::SetEpsilonForNodeComp(double val)
328 _EPS_FOR_NODE_COMP=val;
332 * 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.
334 void MEDLoader::SetCompPolicyForCell(int val)
340 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
341 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
343 void MEDLoader::SetTooLongStrPolicy(int val)
349 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
350 * It returns, in this order :
351 * - 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...
352 * - the mesh dimension
353 * - the space dimension
354 * - the number of nodes
356 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)
358 CheckFileForRead(fileName);
359 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
361 char nommaa[MED_NAME_SIZE+1];
362 char maillage_description[MED_COMMENT_SIZE+1];
363 med_mesh_type type_maillage;
364 std::string trueMeshName;
365 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
366 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
367 med_sorting_type sortingType;
369 med_axis_type axisType;
370 int naxis(MEDmeshnAxis(fid,meshId));
371 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
372 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
373 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
374 if(type_maillage!=MED_UNSTRUCTURED_MESH)
376 std::ostringstream oss; oss << "MEDLoader::GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
377 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
378 throw INTERP_KERNEL::Exception(oss.str().c_str());
382 throw INTERP_KERNEL::Exception("MEDLoader::GetUMeshGlobalInfo : multisteps on mesh not managed !");
385 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
387 std::vector<int> dims;
388 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
389 med_bool changement,transformation;
390 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
392 med_geometry_type curMedType=typmai[i];
393 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
396 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
397 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
398 dims.push_back(mdimCell);
399 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
402 int maxLev=*std::max_element(dims.begin(),dims.end());
403 int lowLev=*std::min_element(dims.begin(),dims.end());
404 int nbOfLevels=maxLev-lowLev+1;
405 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
406 for(std::size_t i=0;i<dims.size();i++)
408 ret[maxLev-dims[i]].push_back(geoTypes[i]);
410 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
414 void MEDLoader::CheckFileForRead(const std::string& fileName)
416 MEDFileUtilities::CheckFileForRead(fileName);
419 std::vector<std::string> MEDLoader::GetMeshNames(const std::string& fileName)
421 CheckFileForRead(fileName);
422 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
423 std::vector<std::string> ret=MEDLoaderNS::getMeshNamesFid(fid);
427 std::vector< std::pair<std::string,std::string> > MEDLoader::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
429 CheckFileForRead(fileName);
430 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
431 med_int nbFields(MEDnField(fid));
432 std::vector<std::string> fields(nbFields);
433 med_field_type typcha;
434 for(int i=0;i<nbFields;i++)
436 med_int ncomp(MEDfieldnComponent(fid,i+1));
437 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
438 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
439 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
442 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
443 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
444 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
445 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
446 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
447 if(curFieldName==fieldName)
449 std::vector< std::pair<std::string,std::string> > ret(ncomp);
450 for(int j=0;j<ncomp;j++)
451 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
452 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
455 fields[i]=curFieldName;
457 std::ostringstream oss; oss << "MEDLoader::GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
458 oss << "Possible field names are : " << std::endl;
459 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
460 throw INTERP_KERNEL::Exception(oss.str().c_str());
463 std::vector<std::string> MEDLoader::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
465 CheckFileForRead(fileName);
466 std::vector<std::string> ret;
468 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
469 med_int nbFields=MEDnField(fid);
471 med_field_type typcha;
472 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
473 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
476 for(int i=0;i<nbFields;i++)
478 med_int ncomp(MEDfieldnComponent(fid,i+1));
479 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
480 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
482 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
483 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
484 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
485 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
486 if(curFieldName==fieldName)
487 ret.push_back(meshName);
492 std::vector<std::string> MEDLoader::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
494 CheckFileForRead(fileName);
495 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
496 med_int nfam=MEDnFamily(fid,meshName.c_str());
497 std::vector<std::string> ret(nfam);
498 char nomfam[MED_NAME_SIZE+1];
500 for(int i=0;i<nfam;i++)
502 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
503 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
504 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
505 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
506 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
507 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
508 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
509 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
516 std::vector<std::string> MEDLoader::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
518 CheckFileForRead(fileName);
519 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
520 med_int nfam=MEDnFamily(fid,meshName.c_str());
521 std::vector<std::string> ret;
522 char nomfam[MED_NAME_SIZE+1];
524 for(int i=0;i<nfam;i++)
526 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
527 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
528 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
529 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
530 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
531 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
532 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
533 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
534 for(int j=0;j<ngro;j++)
536 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
544 std::vector<std::string> MEDLoader::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
546 CheckFileForRead(fileName);
547 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
548 med_int nfam=MEDnFamily(fid,meshName.c_str());
549 std::vector<std::string> ret;
550 char nomfam[MED_NAME_SIZE+1];
553 for(int i=0;i<nfam && !found;i++)
555 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
556 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
557 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
558 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
559 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
560 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
561 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
562 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
563 found=(cur==famName);
565 for(int j=0;j<ngro;j++)
567 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
573 std::ostringstream oss;
574 oss << "MEDLoader::GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
575 throw INTERP_KERNEL::Exception(oss.str().c_str());
581 std::vector<std::string> MEDLoader::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
583 CheckFileForRead(fileName);
584 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
585 med_int nfam=MEDnFamily(fid,meshName.c_str());
586 std::vector<std::string> ret;
587 char nomfam[MED_NAME_SIZE+1];
589 for(int i=0;i<nfam;i++)
591 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
592 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
593 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
594 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
595 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
596 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
597 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
598 for(int j=0;j<ngro;j++)
600 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
601 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
608 std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
610 std::vector<ParaMEDMEM::TypeOfField> ret;
611 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeFieldMultiTS> fs(MEDFileAnyTypeFieldMultiTS::New(fileName,fieldName,false));
612 if(fs->getMeshName()!=meshName)
614 std::ostringstream oss; oss << "MEDLoader::GetTypesOfField : The field \"" << fieldName << "\" in file \"" << fileName << "\" is not lying on mesh \"" << meshName << "\"";
615 oss << " The name of the mesh in file is \"" << fs->getMeshName() << "\"!";
616 throw INTERP_KERNEL::Exception(oss.str().c_str());
618 int nbTS(fs->getNumberOfTS());
621 for(int i=0;i<nbTS;i++)
623 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> f1ts(fs->getTimeStepAtPos(i));
624 std::vector<ParaMEDMEM::TypeOfField> tof(f1ts->getTypesOfFieldAvailable());
625 for(std::vector<ParaMEDMEM::TypeOfField>::const_iterator it=tof.begin();it!=tof.end();it++)
626 if(std::find(ret.begin(),ret.end(),*it)==ret.end())
629 // sort ret to put before ON_NODES then ON_CELLS then the remaining.
630 std::vector<ParaMEDMEM::TypeOfField> ret2;
631 if(std::find(ret.begin(),ret.end(),ON_NODES)!=ret.end())
632 ret2.push_back(ON_NODES);
633 if(std::find(ret.begin(),ret.end(),ON_CELLS)!=ret.end())
634 ret2.push_back(ON_CELLS);
635 for(std::vector<ParaMEDMEM::TypeOfField>::const_iterator it=ret.begin();it!=ret.end();it++)
636 if(*it!=ON_NODES && *it!=ON_CELLS)
641 std::vector<std::string> MEDLoader::GetAllFieldNames(const std::string& fileName)
643 CheckFileForRead(fileName);
644 std::vector<std::string> ret;
645 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
646 med_int nbFields=MEDnField(fid);
647 med_field_type typcha;
648 for(int i=0;i<nbFields;i++)
650 med_int ncomp(MEDfieldnComponent(fid,i+1));
651 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
652 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
653 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
654 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
655 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
658 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
659 ret.push_back(std::string(nomcha));
664 std::vector<std::string> MEDLoader::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
666 CheckFileForRead(fileName);
667 std::vector<std::string> ret;
668 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
669 med_int nbFields=MEDnField(fid);
671 med_field_type typcha;
672 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
673 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
675 for(int i=0;i<nbFields;i++)
677 med_int ncomp(MEDfieldnComponent(fid,i+1));
678 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
679 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
680 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
683 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
684 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
685 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
687 if(curMeshName==meshName)
688 ret.push_back(curFieldName);
695 std::vector<std::string> MEDLoader::GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName)
697 CheckFileForRead(fileName);
701 return GetCellFieldNamesOnMesh(fileName,meshName);
703 return GetNodeFieldNamesOnMesh(fileName,meshName);
705 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
709 std::vector<std::string> MEDLoader::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
711 CheckFileForRead(fileName);
712 std::vector<std::string> ret;
713 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
714 med_int nbFields=MEDnField(fid);
716 med_field_type typcha;
717 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
718 med_int numdt=0,numo=0;
720 char pflname[MED_NAME_SIZE+1]="";
721 char locname[MED_NAME_SIZE+1]="";
722 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
723 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
724 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
728 for(int i=0;i<nbFields;i++)
730 med_int ncomp(MEDfieldnComponent(fid,i+1));
731 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
732 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
733 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
734 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
735 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
737 if(curMeshName==meshName)
740 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
744 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
745 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
746 pflname,&profilesize,locname,&nbi));
750 ret.push_back(curFieldName);
759 std::vector<std::string> MEDLoader::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
761 CheckFileForRead(fileName);
762 std::vector<std::string> ret;
763 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
764 med_int nbFields=MEDnField(fid);
765 char pflname[MED_NAME_SIZE+1]="";
766 char locname[MED_NAME_SIZE+1]="";
768 med_field_type typcha;
769 med_int numdt=0,numo=0;
771 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
772 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
773 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
776 for(int i=0;i<nbFields;i++)
778 med_int ncomp(MEDfieldnComponent(fid,i+1));
779 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
780 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
782 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
783 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
784 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
788 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
789 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
790 pflname,&profilesize,locname,&nbi));
791 if(curMeshName==meshName && nbOfVal>0)
793 ret.push_back(curFieldName);
800 std::vector< std::pair< std::pair<int,int>, double> > MEDLoader::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
802 CheckFileForRead(fileName);
803 std::vector< std::pair< std::pair<int,int>, double > > ret;
804 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
805 med_int nbFields=MEDnField(fid);
807 med_field_type typcha;
808 med_int numdt=0,numo=0;
810 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
811 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
812 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
815 std::ostringstream oss; oss << "MEDLoader::GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
816 for(int i=0;i<nbFields;i++)
818 med_int ncomp(MEDfieldnComponent(fid,i+1));
819 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
820 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
822 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
823 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
824 if(curFieldName==fieldName)
826 for(int k=0;k<nbPdt;k++)
828 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
829 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
835 oss << "\"" << curFieldName << "\"";
836 if(i!=nbFields-1) oss << ", ";
840 throw INTERP_KERNEL::Exception(oss.str().c_str());
843 double MEDLoader::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
845 CheckFileForRead(fileName);
846 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
847 med_int nbFields=MEDnField(fid);
849 med_field_type typcha;
850 med_int numdt=0,numo=0;
853 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
854 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
855 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
859 double ret=std::numeric_limits<double>::max();
860 for(int i=0;i<nbFields && !found;i++)
862 med_int ncomp(MEDfieldnComponent(fid,i+1));
863 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
864 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
866 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt));
867 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
868 if(curFieldName==fieldName)
871 for(int k=0;k<nbPdt;k++)
873 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
874 if(numdt==iteration && numo==order)
882 if(!found || !found2)
884 std::ostringstream oss;
885 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
886 throw INTERP_KERNEL::Exception(oss.str().c_str());
891 std::vector< std::pair<int,int> > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
893 CheckFileForRead(fileName);
897 return GetCellFieldIterations(fileName,meshName,fieldName);
899 return GetNodeFieldIterations(fileName,meshName,fieldName);
901 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
905 std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
907 CheckFileForRead(fileName);
908 std::string meshNameCpp(meshName);
909 std::vector< std::pair<int,int> > ret;
910 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
911 med_int nbFields=MEDnField(fid);
913 med_field_type typcha;
914 med_int numdt=0,numo=0;
916 char pflname[MED_NAME_SIZE+1]="";
917 char locname[MED_NAME_SIZE+1]="";
918 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
919 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
920 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
923 std::ostringstream oss; oss << "MEDLoader::GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
924 std::set<std::string> s2;
925 for(int i=0;i<nbFields;i++)
927 med_int ncomp(MEDfieldnComponent(fid,i+1));
928 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
929 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
931 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
932 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
933 if(curFieldName==fieldName)
936 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
938 for(int k=0;k<nbPdt;k++)
941 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
942 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
943 pflname,&profilesize,locname,&nbi));
944 std::string maa_ass_cpp(maa_ass);
947 if(meshNameCpp==maa_ass_cpp)
950 ret.push_back(std::make_pair(numdt,numo));
953 s2.insert(maa_ass_cpp);
960 oss << "\"" << curFieldName << "\"";
961 if(i!=nbFields-1) oss << ", ";
968 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
969 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
972 throw INTERP_KERNEL::Exception(oss.str().c_str());
977 std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
979 CheckFileForRead(fileName);
980 std::string meshNameCpp(meshName);
981 std::vector< std::pair<int,int> > ret;
982 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
983 med_int nbFields=MEDnField(fid);
985 med_field_type typcha;
986 med_int numdt=0,numo=0;
988 char pflname[MED_NAME_SIZE+1]="";
989 char locname[MED_NAME_SIZE+1]="";
990 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
991 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
992 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
995 std::ostringstream oss; oss << "MEDLoader::GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
996 std::set<std::string> s2;
997 for(int i=0;i<nbFields;i++)
999 med_int ncomp(MEDfieldnComponent(fid,i+1));
1000 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
1001 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1003 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
1004 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1005 if(curFieldName==fieldName)
1007 for(int k=0;k<nbPdt;k++)
1009 int profilesize,nbi;
1010 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
1011 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1012 pflname,&profilesize,locname,&nbi));
1013 std::string maa_ass_cpp(maa_ass);
1016 if(meshNameCpp==maa_ass_cpp)
1017 { ret.push_back(std::make_pair(numdt,numo)); }
1019 s2.insert(maa_ass_cpp);
1025 oss << "\"" << curFieldName << "\"";
1026 if(i!=nbFields-1) oss << ", ";
1033 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
1034 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
1037 throw INTERP_KERNEL::Exception(oss.str().c_str());
1042 ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1044 CheckFileForRead(fileName);
1045 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1046 MEDFileMesh *mmPtr(mm);
1047 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1049 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1050 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1053 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1054 return const_cast<MEDCouplingCMesh *>(ret);
1056 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1059 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1060 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1062 std::ostringstream oss; oss << "MEDLoader::ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1063 throw INTERP_KERNEL::Exception(oss.str().c_str());
1066 ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1068 CheckFileForRead(fileName);
1069 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1070 MEDFileMesh *mmPtr(mm);
1071 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1073 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1074 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1077 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1078 return const_cast<MEDCouplingCMesh *>(ret);
1080 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1083 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1084 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1086 std::ostringstream oss; oss << "MEDLoader::ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1087 throw INTERP_KERNEL::Exception(oss.str().c_str());
1090 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1092 CheckFileForRead(fileName);
1093 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1094 MEDFileMesh *mmPtr(mm);
1095 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1098 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1099 throw INTERP_KERNEL::Exception(oss.str().c_str());
1101 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1104 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1106 CheckFileForRead(fileName);
1107 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1108 MEDFileMesh *mmPtr(mm);
1109 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1112 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1113 throw INTERP_KERNEL::Exception(oss.str().c_str());
1115 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1118 int MEDLoader::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1120 CheckFileForRead(fileName);
1121 std::vector<int> poss;
1122 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1125 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1127 CheckFileForRead(fileName);
1128 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1129 MEDFileMesh *mmPtr(mm);
1130 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1133 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromFamilies : 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->getFamilies(meshDimRelToMax,fams,true);
1139 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1141 CheckFileForRead(fileName);
1142 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1143 MEDFileMesh *mmPtr(mm);
1144 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1147 std::ostringstream oss; oss << "MEDLoader::ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1148 throw INTERP_KERNEL::Exception(oss.str().c_str());
1150 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1153 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)
1155 CheckFileForRead(fileName);
1159 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1161 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1163 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1165 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1167 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1171 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsOnSameMesh(ParaMEDMEM::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1172 const std::vector<std::pair<int,int> >& its)
1175 return std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>();
1176 CheckFileForRead(fileName);
1177 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> ret(its.size());
1178 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> > retSafe(its.size());
1181 //Retrieving mesh of rank 0 and field on rank 0 too.
1182 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1183 MEDFileMesh *mmPtr(mm);
1184 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1186 throw INTERP_KERNEL::Exception("MEDLoader::ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1187 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1188 const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1189 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m2(m->clone(true));
1191 m2->renumberCells(o2n->begin(),true);
1193 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1195 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1196 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1198 retElt->renumberCells(o2n->begin(),true);
1199 retElt->setMesh(m2);
1203 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1204 ret[i]=retSafe[i].retn();
1208 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1209 const std::vector<std::pair<int,int> >& its)
1211 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1214 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1215 const std::vector<std::pair<int,int> >& its)
1217 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1220 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1221 const std::vector<std::pair<int,int> >& its)
1223 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1226 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1227 const std::vector<std::pair<int,int> >& its)
1229 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1232 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1234 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1235 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1236 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1237 MEDFileMesh *mPtr(mm);
1238 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1239 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_CELLS,m);
1242 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1244 ret->renumberCells(num->begin());
1249 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1251 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1252 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1253 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1254 MEDFileMesh *mPtr(mm);
1255 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_NODES,m);
1256 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1257 if(ff->getPflsReallyUsed().empty())
1261 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1263 ret->renumberCells(num->begin());
1268 DataArrayInt *pfl=0,*arr2=0;
1269 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr=ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl);
1270 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflSafe(pfl);
1271 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> mp=m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end());
1272 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mzip=static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2));
1273 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2Safe(arr2);
1274 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr3=arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes());
1275 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflSorted(pflSafe->deepCpy()); pflSorted->sort(true);
1276 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1277 throw INTERP_KERNEL::Exception("MEDLoader::ReadFieldNode : not implemented yet !");
1278 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1280 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n2=pflSafe->checkAndPreparePermutation();
1281 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o2=o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples());
1282 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1291 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1293 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1294 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1295 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1296 MEDFileMesh *mPtr(mm);
1297 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1298 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m);
1301 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1303 ret->renumberCells(num->begin());
1308 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1310 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,iteration,order);
1311 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1312 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> m=mm->getGenMeshAtLevel(meshDimRelToMax,false);
1313 MEDFileMesh *mPtr(mm);
1314 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1315 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret=ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m);
1318 const DataArrayInt *num=muPtr->getNumberFieldAtLevel(meshDimRelToMax);
1320 ret->renumberCells(num->begin());
1325 void MEDLoader::WriteMesh(const std::string& fileName, const ParaMEDMEM::MEDCouplingMesh *mesh, bool writeFromScratch)
1328 throw INTERP_KERNEL::Exception("MEDLoader::WriteMesh : input mesh is null !");
1329 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1332 WriteUMesh(fileName,um,writeFromScratch);
1335 int mod=writeFromScratch?2:0;
1336 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1339 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
1340 AssignStaticWritePropertiesTo(*mmu);
1341 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1342 mmu->write(fileName,mod);
1345 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1348 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc(MEDFileCMesh::New());
1349 AssignStaticWritePropertiesTo(*mmc);
1350 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1351 mmc->write(fileName,mod);
1354 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1357 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1358 AssignStaticWritePropertiesTo(*mmc);
1359 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1360 mmc->write(fileName,mod);
1363 throw INTERP_KERNEL::Exception("MEDLoader::WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1366 void MEDLoader::WriteUMesh(const std::string& fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch)
1369 throw INTERP_KERNEL::Exception("MEDLoader::WriteUMesh : input mesh is null !");
1370 int mod=writeFromScratch?2:0;
1371 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
1372 AssignStaticWritePropertiesTo(*m);
1373 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCpy()));
1374 m->setMeshAtLevel(0,mcpy,true);
1375 m->write(fileName,mod);
1378 void MEDLoader::WriteUMeshDep(const std::string& fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch)
1380 MEDLoader::WriteUMesh(fileName,mesh,writeFromScratch);
1383 void MEDLoader::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1385 std::string meshName(meshNameC);
1386 if(meshName.empty())
1387 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 !");
1388 int status=MEDLoaderBase::getStatusOfFile(fileName);
1389 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1391 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1392 throw INTERP_KERNEL::Exception(oss.str().c_str());
1394 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
1395 AssignStaticWritePropertiesTo(*m);
1396 m->setGroupsFromScratch(0,meshes,true);
1397 m->setName(meshNameC);
1398 int mod=writeFromScratch?2:0;
1399 m->write(fileName,mod);
1402 void MEDLoader::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1404 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1407 void MEDLoader::WriteUMeshes(const std::string& fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1409 int mod=writeFromScratch?2:0;
1410 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
1411 AssignStaticWritePropertiesTo(*m);
1412 m->setMeshes(meshes,true);
1413 m->write(fileName,mod);
1416 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1418 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff(MEDFileField1TS::New());
1419 MEDLoader::AssignStaticWritePropertiesTo(*ff);
1420 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1421 const MEDCouplingMesh *m(f2->getMesh());
1422 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1423 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1424 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1425 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1426 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm;
1427 int mod=writeFromScratch?2:0;
1430 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
1431 MEDLoader::AssignStaticWritePropertiesTo(*mmu);
1432 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(um->getRenumArrForMEDFileFrmt());
1433 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1434 f2->renumberCells(o2n->begin(),false);
1435 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1436 mmu->setRenumFieldArr(0,n2o);
1437 ff->setFieldNoProfileSBT(f2);
1438 mmu->write(fileName,mod);
1442 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
1443 MEDLoader::AssignStaticWritePropertiesTo(*mmu);
1444 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1445 ff->setFieldNoProfileSBT(f2);
1446 mmu->write(fileName,mod);
1450 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc(MEDFileCMesh::New());
1451 MEDLoader::AssignStaticWritePropertiesTo(*mmc);
1452 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1453 ff->setFieldNoProfileSBT(f2);
1454 mmc->write(fileName,mod);
1458 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1459 MEDLoader::AssignStaticWritePropertiesTo(*mmc);
1460 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1461 ff->setFieldNoProfileSBT(f2);
1462 mmc->write(fileName,mod);
1465 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1466 ff->write(fileName,0);
1469 void MEDLoader::WriteField(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1472 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : input field is NULL !");
1473 f->checkCoherency();
1474 int status=MEDLoaderBase::getStatusOfFile(fileName);
1475 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1477 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1478 throw INTERP_KERNEL::Exception(oss.str().c_str());
1480 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1482 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
1486 std::vector<std::string> meshNames=GetMeshNames(fileName);
1488 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : trying to write a field with no mesh !");
1489 std::string fileNameCpp(f->getMesh()->getName());
1490 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1491 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
1494 MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1495 AssignStaticWritePropertiesTo(*mm);
1496 const MEDFileMesh *mmPtr(mm);
1497 const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
1499 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : only umeshes are supported now !");
1500 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1501 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1503 throw INTERP_KERNEL::Exception("MEDLoader::WriteField : only umesh in input field supported !");
1504 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1505 f2->renumberCells(o2n->begin(),false);
1506 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1507 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
1508 if(f2->getTypeOfField()!=ON_NODES)
1510 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1511 DataArrayInt *part=0;
1512 bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
1513 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> partSafe(part);
1516 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 !";
1517 throw INTERP_KERNEL::Exception(oss.str().c_str());
1519 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1520 AssignStaticWritePropertiesTo(*f1ts);
1521 if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfCells())
1522 f1ts->setFieldNoProfileSBT(f2);
1525 part->setName(f1ts->createNewNameOfPfl().c_str());
1526 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1528 f1ts->write(fileName,0);
1533 DataArrayInt *part=0;
1534 bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
1535 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> partSafe(part);
1538 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 !";
1539 throw INTERP_KERNEL::Exception(oss.str().c_str());
1541 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1542 AssignStaticWritePropertiesTo(*f1ts);
1543 if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfNodes())
1544 f1ts->setFieldNoProfileSBT(f2);
1547 part->setName(f1ts->createNewNameOfPfl().c_str());
1548 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1550 f1ts->write(fileName,0);
1556 void MEDLoader::WriteFieldDep(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
1558 WriteField(fileName,f,writeFromScratch);
1561 void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f)
1564 throw INTERP_KERNEL::Exception("MEDLoader::WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1565 f->checkCoherency();
1566 int status=MEDLoaderBase::getStatusOfFile(fileName);
1567 if(status!=MEDLoaderBase::EXIST_RW)
1569 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1570 throw INTERP_KERNEL::Exception(oss.str().c_str());
1572 MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1573 AssignStaticWritePropertiesTo(*f1ts);
1574 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1577 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
1578 MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
1579 f2->renumberCells(o2n->begin(),false);
1580 f1ts->setFieldNoProfileSBT(f2);
1583 f1ts->setFieldNoProfileSBT(f);
1584 f1ts->write(fileName,0);