1 // Copyright (C) 2007-2016 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 "MEDLoaderNS.hxx"
25 #include "MEDFileSafeCaller.txx"
26 #include "MEDFileMesh.hxx"
27 #include "MEDFileField.hxx"
28 #include "CellModel.hxx"
29 #include "MEDCouplingUMesh.hxx"
30 #include "MEDCouplingMemArray.hxx"
31 #include "MEDCouplingFieldDouble.hxx"
32 #include "MEDCouplingGaussLocalization.hxx"
35 #include "InterpKernelAutoPtr.hxx"
49 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
73 med_geometry_type typmainoeud[1] = { MED_NONE };
75 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
76 INTERP_KERNEL::NORM_SEG2,
77 INTERP_KERNEL::NORM_SEG3,
78 INTERP_KERNEL::NORM_SEG4,
79 INTERP_KERNEL::NORM_TRI3,
80 INTERP_KERNEL::NORM_QUAD4,
81 INTERP_KERNEL::NORM_TRI6,
82 INTERP_KERNEL::NORM_TRI7,
83 INTERP_KERNEL::NORM_QUAD8,
84 INTERP_KERNEL::NORM_QUAD9,
85 INTERP_KERNEL::NORM_TETRA4,
86 INTERP_KERNEL::NORM_PYRA5,
87 INTERP_KERNEL::NORM_PENTA6,
88 INTERP_KERNEL::NORM_HEXA8,
89 INTERP_KERNEL::NORM_HEXGP12,
90 INTERP_KERNEL::NORM_TETRA10,
91 INTERP_KERNEL::NORM_PYRA13,
92 INTERP_KERNEL::NORM_PENTA15,
93 INTERP_KERNEL::NORM_HEXA20,
94 INTERP_KERNEL::NORM_HEXA27,
95 INTERP_KERNEL::NORM_POLYGON,
96 INTERP_KERNEL::NORM_QPOLYG,
97 INTERP_KERNEL::NORM_POLYHED };
99 med_geometry_type typmai3[34] = { MED_POINT1,//0
135 double _EPS_FOR_NODE_COMP=1.e-12;
137 int _COMP_FOR_CELL=0;
141 using namespace MEDCoupling;
146 * This method returns a first quick overview of mesh with name \a meshName into the file \a fileName.
147 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
148 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
150 int MEDLoaderNS::readUMeshDimFromFile(const std::string& fileName, const std::string& meshName, std::vector<int>& possibilities)
152 possibilities.clear();
153 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
156 char nommaa[MED_NAME_SIZE+1];
157 char maillage_description[MED_COMMENT_SIZE+1];
158 med_mesh_type type_maillage;
160 std::string trueMeshName;
161 med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
162 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
163 med_sorting_type sortingType;
165 med_axis_type axisType;
166 int naxis(MEDmeshnAxis(fid,meshId));
167 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
168 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
169 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
173 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
177 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
179 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
181 med_geometry_type curMedType=typmai[i];
182 med_bool changement,transformation;
183 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
184 int curNbOfElemF(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));//limitation
186 med_entity_type whichEntity;
187 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
190 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
191 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
198 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
199 possibilities.push_back(*it-ret);
206 med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const std::string& meshName, std::string& trueMeshName)
210 std::vector<std::string> meshes=getMeshNamesFid(fid);
212 throw INTERP_KERNEL::Exception("No mesh in file");
213 trueMeshName=meshes[0];
216 std::string meshNameStr(meshName);
217 std::vector<std::string> meshes=getMeshNamesFid(fid);
219 throw INTERP_KERNEL::Exception("No mesh in file");
220 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
221 if(iter==meshes.end())
223 std::ostringstream os2;
224 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
225 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
226 throw INTERP_KERNEL::Exception(os2.str().c_str());
228 trueMeshName=meshName;
229 return iter-meshes.begin()+1;
232 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
234 med_mesh_type type_maillage;
235 char maillage_description[MED_COMMENT_SIZE+1];
236 char dtunit[MED_COMMENT_SIZE+1];
239 char nommaa[MED_NAME_SIZE+1];
240 med_axis_type axistype;
241 med_sorting_type stype;
242 med_int n=MEDnMesh(fid);
243 std::vector<std::string> ret(n);
246 int naxis(MEDmeshnAxis(fid,i+1));
247 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
248 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
250 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
251 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
258 * This methods allows to merger all entities and to considerate only cell types.
260 void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
262 if(nbOfElemCell>=nbOfElemFace)
264 whichEntity=MED_CELL;
265 nbOfElem=nbOfElemCell;
269 whichEntity=MED_CELL;
270 nbOfElem=nbOfElemFace;
276 void MEDCoupling::AssignStaticWritePropertiesTo(MEDCoupling::MEDFileWritable& obj)
278 obj.setTooLongStrPolicy(_TOO_LONG_STR);
281 bool MEDCoupling::HasXDR()
290 std::string MEDCoupling::MEDFileVersionStr()
292 return std::string(MED_VERSION_STR);
295 void MEDCoupling::MEDFileVersion(int& major, int& minor, int& release)
297 major=MED_NUM_MAJEUR;
298 minor=MED_NUM_MINEUR;
299 release=MED_NUM_RELEASE;
303 * 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.
305 void MEDCoupling::SetEpsilonForNodeComp(double val)
307 _EPS_FOR_NODE_COMP=val;
311 * 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.
313 void MEDCoupling::SetCompPolicyForCell(int val)
319 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
320 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
322 void MEDCoupling::SetTooLongStrPolicy(int val)
328 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
329 * It returns, in this order :
330 * - 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...
331 * - the mesh dimension
332 * - the space dimension
333 * - the number of nodes
335 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > MEDCoupling::GetUMeshGlobalInfo(const std::string& fileName, const std::string& meshName, int &meshDim, int& spaceDim, int& numberOfNodes)
337 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
339 char nommaa[MED_NAME_SIZE+1];
340 char maillage_description[MED_COMMENT_SIZE+1];
341 med_mesh_type type_maillage;
342 std::string trueMeshName;
343 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
344 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
345 med_sorting_type sortingType;
347 med_axis_type axisType;
348 int naxis(MEDmeshnAxis(fid,meshId));
349 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
350 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
351 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit));
352 if(type_maillage!=MED_UNSTRUCTURED_MESH)
354 std::ostringstream oss; oss << "GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
355 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
356 throw INTERP_KERNEL::Exception(oss.str().c_str());
360 throw INTERP_KERNEL::Exception("GetUMeshGlobalInfo : multisteps on mesh not managed !");
363 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,nommaa,1,&numdt,&numit,&dt));
365 std::vector<int> dims;
366 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
367 med_bool changement,transformation;
368 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
370 med_geometry_type curMedType=typmai[i];
371 int curNbOfElemM(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation));
374 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
375 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
376 dims.push_back(mdimCell);
377 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
380 int maxLev=*std::max_element(dims.begin(),dims.end());
381 int lowLev=*std::min_element(dims.begin(),dims.end());
382 int nbOfLevels=maxLev-lowLev+1;
383 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
384 for(std::size_t i=0;i<dims.size();i++)
386 ret[maxLev-dims[i]].push_back(geoTypes[i]);
388 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
392 void MEDCoupling::CheckFileForRead(const std::string& fileName)
394 MEDFileUtilities::CheckFileForRead(fileName);
397 std::vector<std::string> MEDCoupling::GetMeshNames(const std::string& fileName)
399 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
400 return MEDLoaderNS::getMeshNamesFid(fid);
403 std::vector< std::pair<std::string,std::string> > MEDCoupling::GetComponentsNamesOfField(const std::string& fileName, const std::string& fieldName)
405 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
406 med_int nbFields(MEDnField(fid));
407 std::vector<std::string> fields(nbFields);
408 med_field_type typcha;
409 for(int i=0;i<nbFields;i++)
411 med_int ncomp(MEDfieldnComponent(fid,i+1));
412 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
413 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
414 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
417 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
418 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
419 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
420 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
421 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
422 if(curFieldName==fieldName)
424 std::vector< std::pair<std::string,std::string> > ret(ncomp);
425 for(int j=0;j<ncomp;j++)
426 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
427 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
430 fields[i]=curFieldName;
432 std::ostringstream oss; oss << "GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
433 oss << "Possible field names are : " << std::endl;
434 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
435 throw INTERP_KERNEL::Exception(oss.str().c_str());
438 std::vector<std::string> MEDCoupling::GetMeshNamesOnField(const std::string& fileName, const std::string& fieldName)
440 std::vector<std::string> ret;
442 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
443 med_int nbFields=MEDnField(fid);
445 med_field_type typcha;
446 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
447 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
450 for(int i=0;i<nbFields;i++)
452 med_int ncomp(MEDfieldnComponent(fid,i+1));
453 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
454 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
456 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
457 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
458 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
459 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
460 if(curFieldName==fieldName)
461 ret.push_back(meshName);
466 std::vector<std::string> MEDCoupling::GetMeshFamiliesNames(const std::string& fileName, const std::string& meshName)
468 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
469 med_int nfam=MEDnFamily(fid,meshName.c_str());
470 std::vector<std::string> ret(nfam);
471 char nomfam[MED_NAME_SIZE+1];
473 for(int i=0;i<nfam;i++)
475 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
476 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
477 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
478 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
479 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
480 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
481 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
482 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
489 std::vector<std::string> MEDCoupling::GetMeshFamiliesNamesOnGroup(const std::string& fileName, const std::string& meshName, const std::string& grpName)
491 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
492 med_int nfam=MEDnFamily(fid,meshName.c_str());
493 std::vector<std::string> ret;
494 char nomfam[MED_NAME_SIZE+1];
496 for(int i=0;i<nfam;i++)
498 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
499 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
500 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
501 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
502 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
503 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
504 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
505 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
506 for(int j=0;j<ngro;j++)
508 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
516 std::vector<std::string> MEDCoupling::GetMeshGroupsNamesOnFamily(const std::string& fileName, const std::string& meshName, const std::string& famName)
518 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
519 med_int nfam(MEDnFamily(fid,meshName.c_str()));
520 std::vector<std::string> ret;
521 char nomfam[MED_NAME_SIZE+1];
524 for(int i=0;i<nfam && !found;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 found=(cur==famName);
536 for(int j=0;j<ngro;j++)
538 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
544 std::ostringstream oss;
545 oss << "GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
546 throw INTERP_KERNEL::Exception(oss.str().c_str());
552 std::vector<std::string> MEDCoupling::GetMeshGroupsNames(const std::string& fileName, const std::string& meshName)
554 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
555 med_int nfam=MEDnFamily(fid,meshName.c_str());
556 std::vector<std::string> ret;
557 char nomfam[MED_NAME_SIZE+1];
559 for(int i=0;i<nfam;i++)
561 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
562 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
563 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
564 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
565 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
566 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
567 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
568 for(int j=0;j<ngro;j++)
570 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
571 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
578 std::vector<MEDCoupling::TypeOfField> MEDCoupling::GetTypesOfField(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
580 std::vector<MEDCoupling::TypeOfField> ret;
581 MCAuto<MEDFileAnyTypeFieldMultiTS> fs(MEDFileAnyTypeFieldMultiTS::New(fileName,fieldName,false));
582 if(fs->getMeshName()!=meshName)
584 std::ostringstream oss; oss << "GetTypesOfField : The field \"" << fieldName << "\" in file \"" << fileName << "\" is not lying on mesh \"" << meshName << "\"";
585 oss << " The name of the mesh in file is \"" << fs->getMeshName() << "\"!";
586 throw INTERP_KERNEL::Exception(oss.str().c_str());
588 int nbTS(fs->getNumberOfTS());
591 for(int i=0;i<nbTS;i++)
593 MCAuto<MEDFileAnyTypeField1TS> f1ts(fs->getTimeStepAtPos(i));
594 std::vector<MEDCoupling::TypeOfField> tof(f1ts->getTypesOfFieldAvailable());
595 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=tof.begin();it!=tof.end();it++)
596 if(std::find(ret.begin(),ret.end(),*it)==ret.end())
599 // sort ret to put before ON_NODES then ON_CELLS then the remaining.
600 std::vector<MEDCoupling::TypeOfField> ret2;
601 if(std::find(ret.begin(),ret.end(),ON_NODES)!=ret.end())
602 ret2.push_back(ON_NODES);
603 if(std::find(ret.begin(),ret.end(),ON_CELLS)!=ret.end())
604 ret2.push_back(ON_CELLS);
605 for(std::vector<MEDCoupling::TypeOfField>::const_iterator it=ret.begin();it!=ret.end();it++)
606 if(*it!=ON_NODES && *it!=ON_CELLS)
611 std::vector<std::string> MEDCoupling::GetAllFieldNames(const std::string& fileName)
613 std::vector<std::string> ret;
614 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
615 med_int nbFields=MEDnField(fid);
616 med_field_type typcha;
617 for(int i=0;i<nbFields;i++)
619 med_int ncomp(MEDfieldnComponent(fid,i+1));
620 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
621 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
622 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
623 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
624 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
627 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
628 ret.push_back(std::string(nomcha));
633 std::vector<std::string> MEDCoupling::GetAllFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
635 std::vector<std::string> ret;
636 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
637 med_int nbFields=MEDnField(fid);
639 med_field_type typcha;
640 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
641 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
643 for(int i=0;i<nbFields;i++)
645 med_int ncomp(MEDfieldnComponent(fid,i+1));
646 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
647 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
648 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
651 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
652 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
653 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
655 if(curMeshName==meshName)
656 ret.push_back(curFieldName);
663 std::vector<std::string> MEDCoupling::GetFieldNamesOnMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName)
665 MEDCoupling::CheckFileForRead(fileName);
669 return GetCellFieldNamesOnMesh(fileName,meshName);
671 return GetNodeFieldNamesOnMesh(fileName,meshName);
673 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
677 std::vector<std::string> MEDCoupling::GetCellFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
679 std::vector<std::string> ret;
680 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
681 med_int nbFields=MEDnField(fid);
683 med_field_type typcha;
684 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
685 med_int numdt=0,numo=0;
687 char pflname[MED_NAME_SIZE+1]="";
688 char locname[MED_NAME_SIZE+1]="";
689 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
690 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
691 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
695 for(int i=0;i<nbFields;i++)
697 med_int ncomp(MEDfieldnComponent(fid,i+1));
698 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
699 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
700 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
701 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
702 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
704 if(curMeshName==meshName)
707 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
711 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
712 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
713 pflname,&profilesize,locname,&nbi));
717 ret.push_back(curFieldName);
726 std::vector<std::string> MEDCoupling::GetNodeFieldNamesOnMesh(const std::string& fileName, const std::string& meshName)
728 std::vector<std::string> ret;
729 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
730 med_int nbFields=MEDnField(fid);
731 char pflname[MED_NAME_SIZE+1]="";
732 char locname[MED_NAME_SIZE+1]="";
734 med_field_type typcha;
735 med_int numdt=0,numo=0;
737 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
738 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
739 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
742 for(int i=0;i<nbFields;i++)
744 med_int ncomp(MEDfieldnComponent(fid,i+1));
745 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
746 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
748 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
749 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
750 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
754 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,1,&numdt,&numo,&dt));
755 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
756 pflname,&profilesize,locname,&nbi));
757 if(curMeshName==meshName && nbOfVal>0)
759 ret.push_back(curFieldName);
766 std::vector< std::pair< std::pair<int,int>, double> > MEDCoupling::GetAllFieldIterations(const std::string& fileName, const std::string& fieldName)
768 std::vector< std::pair< std::pair<int,int>, double > > ret;
769 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
770 med_int nbFields=MEDnField(fid);
772 med_field_type typcha;
773 med_int numdt=0,numo=0;
775 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
776 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
777 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
780 std::ostringstream oss; oss << "GetAllFieldIterations : No field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
781 for(int i=0;i<nbFields;i++)
783 med_int ncomp(MEDfieldnComponent(fid,i+1));
784 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
785 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
787 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
788 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
789 if(curFieldName==fieldName)
791 for(int k=0;k<nbPdt;k++)
793 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
794 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
800 oss << "\"" << curFieldName << "\"";
801 if(i!=nbFields-1) oss << ", ";
805 throw INTERP_KERNEL::Exception(oss.str().c_str());
808 double MEDCoupling::GetTimeAttachedOnFieldIteration(const std::string& fileName, const std::string& fieldName, int iteration, int order)
810 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
811 med_int nbFields=MEDnField(fid);
813 med_field_type typcha;
814 med_int numdt=0,numo=0;
817 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
818 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
819 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
823 double ret=std::numeric_limits<double>::max();
824 for(int i=0;i<nbFields && !found;i++)
826 med_int ncomp(MEDfieldnComponent(fid,i+1));
827 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
828 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
830 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt));
831 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
832 if(curFieldName==fieldName)
835 for(int k=0;k<nbPdt;k++)
837 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
838 if(numdt==iteration && numo==order)
846 if(!found || !found2)
848 std::ostringstream oss;
849 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
850 throw INTERP_KERNEL::Exception(oss.str().c_str());
855 std::vector< std::pair<int,int> > MEDCoupling::GetFieldIterations(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, const std::string& fieldName)
857 MEDCoupling::CheckFileForRead(fileName);
861 return GetCellFieldIterations(fileName,meshName,fieldName);
863 return GetNodeFieldIterations(fileName,meshName,fieldName);
865 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
869 std::vector< std::pair<int,int> > MEDCoupling::GetCellFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
871 std::string meshNameCpp(meshName);
872 std::vector< std::pair<int,int> > ret;
873 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
874 med_int nbFields=MEDnField(fid);
876 med_field_type typcha;
877 med_int numdt=0,numo=0;
879 char pflname[MED_NAME_SIZE+1]="";
880 char locname[MED_NAME_SIZE+1]="";
881 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
882 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
883 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
886 std::ostringstream oss; oss << "GetCellFieldIterations : No cell Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
887 std::set<std::string> s2;
888 for(int i=0;i<nbFields;i++)
890 med_int ncomp(MEDfieldnComponent(fid,i+1));
891 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
892 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
894 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
895 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
896 if(curFieldName==fieldName)
899 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
901 for(int k=0;k<nbPdt;k++)
904 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
905 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
906 pflname,&profilesize,locname,&nbi));
907 std::string maa_ass_cpp(maa_ass);
910 if(meshNameCpp==maa_ass_cpp)
913 ret.push_back(std::make_pair(numdt,numo));
916 s2.insert(maa_ass_cpp);
923 oss << "\"" << curFieldName << "\"";
924 if(i!=nbFields-1) oss << ", ";
931 oss << ". Cell Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
932 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
935 throw INTERP_KERNEL::Exception(oss.str().c_str());
940 std::vector< std::pair<int,int> > MEDCoupling::GetNodeFieldIterations(const std::string& fileName, const std::string& meshName, const std::string& fieldName)
942 std::string meshNameCpp(meshName);
943 std::vector< std::pair<int,int> > ret;
944 MEDFileUtilities::AutoFid fid(MEDCoupling::OpenMEDFileForRead(fileName));
945 med_int nbFields=MEDnField(fid);
947 med_field_type typcha;
948 med_int numdt=0,numo=0;
950 char pflname[MED_NAME_SIZE+1]="";
951 char locname[MED_NAME_SIZE+1]="";
952 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
953 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
954 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
957 std::ostringstream oss; oss << "GetNodeFieldIterations : No node Field field with name \"" << fieldName<< "\" in file \"" << fileName << "\" ! Possible fields are : ";
958 std::set<std::string> s2;
959 for(int i=0;i<nbFields;i++)
961 med_int ncomp(MEDfieldnComponent(fid,i+1));
962 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
963 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
965 MEDFILESAFECALLERRD0(MEDfieldInfo,(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt));
966 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
967 if(curFieldName==fieldName)
969 for(int k=0;k<nbPdt;k++)
972 MEDFILESAFECALLERRD0(MEDfieldComputingStepInfo,(fid,nomcha,k+1,&numdt,&numo,&dt));
973 med_int nbOfVal(MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
974 pflname,&profilesize,locname,&nbi));
975 std::string maa_ass_cpp(maa_ass);
978 if(meshNameCpp==maa_ass_cpp)
979 { ret.push_back(std::make_pair(numdt,numo)); }
981 s2.insert(maa_ass_cpp);
987 oss << "\"" << curFieldName << "\"";
988 if(i!=nbFields-1) oss << ", ";
995 oss << ". Node Field \"" << fieldName << "\" exists but lies on meshes with names : \"";
996 std::copy(s2.begin(),s2.end(),std::ostream_iterator<std::string>(oss,"\", \""));
999 throw INTERP_KERNEL::Exception(oss.str().c_str());
1004 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1006 MEDCoupling::CheckFileForRead(fileName);
1007 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1008 MEDFileMesh *mmPtr(mm);
1009 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1011 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1012 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1015 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1016 return const_cast<MEDCouplingCMesh *>(ret);
1018 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1021 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1022 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1024 std::ostringstream oss; oss << "ReadMeshFromFile : The mesh \"" << meshName << "\" in file \"" << fileName << "\" has not a recognized type !";
1025 throw INTERP_KERNEL::Exception(oss.str().c_str());
1028 MEDCoupling::MEDCouplingMesh *MEDCoupling::ReadMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1030 MEDCoupling::CheckFileForRead(fileName);
1031 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1032 MEDFileMesh *mmPtr(mm);
1033 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1035 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1036 MEDFileCMesh *mmcPtr=dynamic_cast<MEDFileCMesh *>(mmPtr);
1039 const MEDCouplingCMesh *ret(mmcPtr->getMesh()); ret->incrRef();
1040 return const_cast<MEDCouplingCMesh *>(ret);
1042 MEDFileCurveLinearMesh *mmc2Ptr=dynamic_cast<MEDFileCurveLinearMesh *>(mmPtr);
1045 const MEDCouplingCurveLinearMesh *ret(mmc2Ptr->getMesh()); ret->incrRef();
1046 return const_cast<MEDCouplingCurveLinearMesh *>(ret);
1048 std::ostringstream oss; oss << "ReadMeshFromFile (2) : The first mesh \"" << mm->getName() << "\" in file \"" << fileName << "\" has not a recognized type !";
1049 throw INTERP_KERNEL::Exception(oss.str().c_str());
1052 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, const std::string& meshName, int meshDimRelToMax)
1054 MEDCoupling::CheckFileForRead(fileName);
1055 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1056 MEDFileMesh *mmPtr(mm);
1057 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1060 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName=\""<< meshName << "\" exists but it is not an unstructured mesh !";
1061 throw INTERP_KERNEL::Exception(oss.str().c_str());
1063 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1066 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFile(const std::string& fileName, int meshDimRelToMax)
1068 MEDCoupling::CheckFileForRead(fileName);
1069 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName));
1070 MEDFileMesh *mmPtr(mm);
1071 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1074 std::ostringstream oss; oss << "ReadUMeshFromFile : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1075 throw INTERP_KERNEL::Exception(oss.str().c_str());
1077 return mmuPtr->getMeshAtLevel(meshDimRelToMax,true);
1080 int MEDCoupling::ReadUMeshDimFromFile(const std::string& fileName, const std::string& meshName)
1082 MEDCoupling::CheckFileForRead(fileName);
1083 std::vector<int> poss;
1084 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
1087 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromFamilies(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
1089 MEDCoupling::CheckFileForRead(fileName);
1090 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1091 MEDFileMesh *mmPtr(mm);
1092 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1095 std::ostringstream oss; oss << "ReadUMeshFromFamilies : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1096 throw INTERP_KERNEL::Exception(oss.str().c_str());
1098 return mmuPtr->getFamilies(meshDimRelToMax,fams,true);
1101 MEDCoupling::MEDCouplingUMesh *MEDCoupling::ReadUMeshFromGroups(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::vector<std::string>& grps)
1103 MEDCoupling::CheckFileForRead(fileName);
1104 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1105 MEDFileMesh *mmPtr(mm);
1106 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1109 std::ostringstream oss; oss << "ReadUMeshFromGroups : With fileName=\""<< fileName << "\", meshName (the first) =\""<< mm->getName() << "\" exists but it is not an unstructured mesh !";
1110 throw INTERP_KERNEL::Exception(oss.str().c_str());
1112 return mmuPtr->getGroups(meshDimRelToMax,grps,true);
1115 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadField(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1117 MEDCoupling::CheckFileForRead(fileName);
1121 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1123 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1125 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1127 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
1129 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
1133 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsOnSameMesh(MEDCoupling::TypeOfField type, const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1134 const std::vector<std::pair<int,int> >& its)
1137 return std::vector<MEDCoupling::MEDCouplingFieldDouble *>();
1138 MEDCoupling::CheckFileForRead(fileName);
1139 std::vector<MEDCoupling::MEDCouplingFieldDouble *> ret(its.size());
1140 std::vector< MCAuto<MEDCouplingFieldDouble> > retSafe(its.size());
1143 //Retrieving mesh of rank 0 and field on rank 0 too.
1144 MCAuto<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
1145 MEDFileMesh *mmPtr(mm);
1146 MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
1148 throw INTERP_KERNEL::Exception("ReadFieldsOnSameMesh : only unstructured mesh is managed !");
1149 MCAuto<MEDCouplingUMesh> m=mmuPtr->getMeshAtLevel(meshDimRelToMax);
1150 const DataArrayInt *o2n=mmuPtr->getNumberFieldAtLevel(meshDimRelToMax);
1151 MCAuto<MEDCouplingUMesh> m2(m->clone(true));
1153 m2->renumberCells(o2n->begin(),true);
1155 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1157 MCAuto<MEDFileField1TS> ff=MEDFileField1TS::New(fileName,fieldName,(*it).first,(*it).second);
1158 MCAuto<MEDCouplingFieldDouble> retElt=ff->getFieldOnMeshAtLevel(type,m);
1160 retElt->renumberCells(o2n->begin(),true);
1161 retElt->setMesh(m2);
1165 for(std::vector<std::pair<int,int> >::const_iterator it=its.begin();it!=its.end();it++,i++)
1166 ret[i]=retSafe[i].retn();
1170 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsCellOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1171 const std::vector<std::pair<int,int> >& its)
1173 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
1176 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsNodeOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1177 const std::vector<std::pair<int,int> >& its)
1179 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
1182 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1183 const std::vector<std::pair<int,int> >& its)
1185 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
1188 std::vector<MEDCoupling::MEDCouplingFieldDouble *> MEDCoupling::ReadFieldsGaussNEOnSameMesh(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName,
1189 const std::vector<std::pair<int,int> >& its)
1191 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
1194 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldCell(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1196 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1197 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1198 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1199 MEDFileMesh *mPtr(mm);
1200 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1201 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_CELLS,m));
1204 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1206 ret->renumberCells(num->begin());
1211 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldNode(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1213 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1214 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1215 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1216 MEDFileMesh *mPtr(mm);
1217 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_NODES,m));
1218 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1219 if(ff->getPflsReallyUsed().empty())
1223 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1225 ret->renumberCells(num->begin());
1230 DataArrayInt *pfl=0,*arr2=0;
1231 MCAuto<DataArrayDouble> arr(ff->getFieldWithProfile(ON_NODES,meshDimRelToMax,mm,pfl));
1232 MCAuto<DataArrayInt> pflSafe(pfl);
1233 MCAuto<DataArrayInt> mp(m->getCellIdsFullyIncludedInNodeIds(pfl->begin(),pfl->end()));
1234 MCAuto<MEDCouplingUMesh> mzip(static_cast<MEDCouplingUMesh *>(m->buildPartAndReduceNodes(mp->begin(),mp->end(),arr2)));
1235 MCAuto<DataArrayInt> arr2Safe(arr2);
1236 MCAuto<DataArrayInt> arr3(arr2->invertArrayO2N2N2O(mzip->getNumberOfNodes()));
1237 MCAuto<DataArrayInt> pflSorted(pflSafe->deepCopy()); pflSorted->sort(true);
1238 if(!arr3->isEqualWithoutConsideringStr(*pflSorted))
1239 throw INTERP_KERNEL::Exception("ReadFieldNode : not implemented yet !");
1240 if(!arr3->isEqualWithoutConsideringStr(*pflSafe))
1242 MCAuto<DataArrayInt> o2n2(pflSafe->checkAndPreparePermutation());
1243 MCAuto<DataArrayInt> n2o2(o2n2->invertArrayO2N2N2O(o2n2->getNumberOfTuples()));
1244 mzip->renumberNodes(n2o2->begin(),n2o2->getNumberOfTuples());
1253 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGauss(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1255 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1256 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1257 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1258 MEDFileMesh *mPtr(mm);
1259 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1260 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_PT,m));
1263 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1265 ret->renumberCells(num->begin());
1270 MEDCoupling::MEDCouplingFieldDouble *MEDCoupling::ReadFieldGaussNE(const std::string& fileName, const std::string& meshName, int meshDimRelToMax, const std::string& fieldName, int iteration, int order)
1272 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New(fileName,fieldName,iteration,order));
1273 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
1274 MCAuto<MEDCouplingMesh> m(mm->getMeshAtLevel(meshDimRelToMax,false));
1275 MEDFileMesh *mPtr(mm);
1276 MEDFileUMesh *muPtr=dynamic_cast<MEDFileUMesh *>(mPtr);
1277 MCAuto<MEDCouplingFieldDouble> ret(ff->getFieldOnMeshAtLevel(ON_GAUSS_NE,m));
1280 const DataArrayInt *num(muPtr->getNumberFieldAtLevel(meshDimRelToMax));
1282 ret->renumberCells(num->begin());
1287 void MEDCoupling::WriteMesh(const std::string& fileName, const MEDCoupling::MEDCouplingMesh *mesh, bool writeFromScratch)
1290 throw INTERP_KERNEL::Exception("WriteMesh : input mesh is null !");
1291 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(mesh));
1294 WriteUMesh(fileName,um,writeFromScratch);
1297 int mod=writeFromScratch?2:0;
1298 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
1301 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1302 AssignStaticWritePropertiesTo(*mmu);
1303 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1304 mmu->write(fileName,mod);
1307 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
1310 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1311 AssignStaticWritePropertiesTo(*mmc);
1312 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1313 mmc->write(fileName,mod);
1316 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
1319 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1320 AssignStaticWritePropertiesTo(*mmc);
1321 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1322 mmc->write(fileName,mod);
1325 throw INTERP_KERNEL::Exception("WriteMesh : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1328 void MEDCoupling::WriteUMesh(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1331 throw INTERP_KERNEL::Exception("WriteUMesh : input mesh is null !");
1332 int mod=writeFromScratch?2:0;
1333 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1334 AssignStaticWritePropertiesTo(*m);
1335 MCAuto<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCopy()));
1336 m->setMeshAtLevel(0,mcpy,true);
1337 m->write(fileName,mod);
1340 void MEDCoupling::WriteUMeshDep(const std::string& fileName, const MEDCoupling::MEDCouplingUMesh *mesh, bool writeFromScratch)
1342 WriteUMesh(fileName,mesh,writeFromScratch);
1345 void MEDCoupling::WriteUMeshesPartition(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1347 std::string meshName(meshNameC);
1348 if(meshName.empty())
1349 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 !");
1350 int status=MEDLoaderBase::getStatusOfFile(fileName);
1351 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1353 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1354 throw INTERP_KERNEL::Exception(oss.str().c_str());
1356 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1357 AssignStaticWritePropertiesTo(*m);
1358 m->setGroupsFromScratch(0,meshes,true);
1359 m->setName(meshNameC);
1360 int mod=writeFromScratch?2:0;
1361 m->write(fileName,mod);
1364 void MEDCoupling::WriteUMeshesPartitionDep(const std::string& fileName, const std::string& meshNameC, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1366 WriteUMeshesPartition(fileName,meshNameC,meshes,writeFromScratch);
1369 void MEDCoupling::WriteUMeshes(const std::string& fileName, const std::vector<const MEDCoupling::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
1371 int mod=writeFromScratch?2:0;
1372 MCAuto<MEDFileUMesh> m(MEDFileUMesh::New());
1373 AssignStaticWritePropertiesTo(*m);
1374 m->setMeshes(meshes,true);
1375 m->write(fileName,mod);
1378 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1380 MCAuto<MEDFileField1TS> ff(MEDFileField1TS::New());
1381 AssignStaticWritePropertiesTo(*ff);
1382 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1383 const MEDCouplingMesh *m(f2->getMesh());
1384 const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
1385 const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(m));
1386 const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(m));
1387 const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(m));
1388 MCAuto<MEDFileMesh> mm;
1389 int mod=writeFromScratch?2:0;
1392 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1393 AssignStaticWritePropertiesTo(*mmu);
1394 MCAuto<DataArrayInt> o2n(um->getRenumArrForMEDFileFrmt());
1395 MCAuto<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
1396 f2->renumberCells(o2n->begin(),false);
1397 mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
1398 mmu->setRenumFieldArr(0,n2o);
1399 ff->setFieldNoProfileSBT(f2);
1400 mmu->write(fileName,mod);
1404 MCAuto<MEDFileUMesh> mmu(MEDFileUMesh::New());
1405 AssignStaticWritePropertiesTo(*mmu);
1406 mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
1407 ff->setFieldNoProfileSBT(f2);
1408 mmu->write(fileName,mod);
1412 MCAuto<MEDFileCMesh> mmc(MEDFileCMesh::New());
1413 AssignStaticWritePropertiesTo(*mmc);
1414 mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
1415 ff->setFieldNoProfileSBT(f2);
1416 mmc->write(fileName,mod);
1420 MCAuto<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
1421 AssignStaticWritePropertiesTo(*mmc);
1422 mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
1423 ff->setFieldNoProfileSBT(f2);
1424 mmc->write(fileName,mod);
1427 throw INTERP_KERNEL::Exception("MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile : only MEDCouplingUMesh, MEDCoupling1GTUMesh, MEDCouplingCMesh, MEDCouplingCurveLinear are dealed in this API for the moment !");
1428 ff->write(fileName,0);
1431 void MEDCoupling::WriteField(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1434 throw INTERP_KERNEL::Exception("WriteField : input field is NULL !");
1435 f->checkConsistencyLight();
1436 int status=MEDLoaderBase::getStatusOfFile(fileName);
1437 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
1439 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
1440 throw INTERP_KERNEL::Exception(oss.str().c_str());
1442 if(writeFromScratch || (!writeFromScratch && status==MEDLoaderBase::NOT_EXIST))
1444 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,true);
1448 std::vector<std::string> meshNames=GetMeshNames(fileName);
1450 throw INTERP_KERNEL::Exception("WriteField : trying to write a field with no mesh !");
1451 std::string fileNameCpp(f->getMesh()->getName());
1452 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
1453 MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
1456 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
1457 AssignStaticWritePropertiesTo(*mm);
1458 const MEDFileMesh *mmPtr(mm);
1459 const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
1461 throw INTERP_KERNEL::Exception("WriteField : only umeshes are supported now !");
1462 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1463 MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1465 throw INTERP_KERNEL::Exception("WriteField : only umesh in input field supported !");
1466 MCAuto<DataArrayInt> o2n=m->getRenumArrForMEDFileFrmt();
1467 f2->renumberCells(o2n->begin(),false);
1468 m=static_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f2->getMesh()));
1469 MCAuto<MEDCouplingUMesh> mread=mmuPtr->getMeshAtLevel(m->getMeshDimension()-mm->getMeshDimension());
1470 if(f2->getTypeOfField()!=ON_NODES)
1472 m->tryToShareSameCoordsPermute(*mread,_EPS_FOR_NODE_COMP);
1473 DataArrayInt *part=0;
1474 bool b=mread->areCellsIncludedIn(m,_COMP_FOR_CELL,part);
1475 MCAuto<DataArrayInt> partSafe(part);
1478 std::ostringstream oss; oss << "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 !";
1479 throw INTERP_KERNEL::Exception(oss.str().c_str());
1481 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1482 AssignStaticWritePropertiesTo(*f1ts);
1483 if(part->isIota(mread->getNumberOfCells()))
1484 f1ts->setFieldNoProfileSBT(f2);
1487 part->setName(f1ts->createNewNameOfPfl().c_str());
1488 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1490 f1ts->write(fileName,0);
1495 DataArrayInt *part=0;
1496 bool b=mread->getCoords()->areIncludedInMe(m->getCoords(),_EPS_FOR_NODE_COMP,part);
1497 MCAuto<DataArrayInt> partSafe(part);
1500 std::ostringstream oss; oss << "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 !";
1501 throw INTERP_KERNEL::Exception(oss.str().c_str());
1503 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1504 AssignStaticWritePropertiesTo(*f1ts);
1505 if(part->isIota(mread->getNumberOfNodes()))
1506 f1ts->setFieldNoProfileSBT(f2);
1509 part->setName(f1ts->createNewNameOfPfl().c_str());
1510 f1ts->setFieldProfile(f2,mm,m->getMeshDimension()-mm->getMeshDimension(),part);
1512 f1ts->write(fileName,0);
1518 void MEDCoupling::WriteFieldDep(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f, bool writeFromScratch)
1520 WriteField(fileName,f,writeFromScratch);
1523 void MEDCoupling::WriteFieldUsingAlreadyWrittenMesh(const std::string& fileName, const MEDCoupling::MEDCouplingFieldDouble *f)
1526 throw INTERP_KERNEL::Exception("WriteFieldUsingAlreadyWrittenMesh : input field is null !");
1527 f->checkConsistencyLight();
1528 int status=MEDLoaderBase::getStatusOfFile(fileName);
1529 if(status!=MEDLoaderBase::EXIST_RW)
1531 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
1532 throw INTERP_KERNEL::Exception(oss.str().c_str());
1534 MCAuto<MEDFileField1TS> f1ts(MEDFileField1TS::New());
1535 AssignStaticWritePropertiesTo(*f1ts);
1536 MEDCouplingUMesh *m(dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh())));
1539 MCAuto<DataArrayInt> o2n(m->getRenumArrForMEDFileFrmt());
1540 MCAuto<MEDCouplingFieldDouble> f2(f->deepCopy());
1541 f2->renumberCells(o2n->begin(),false);
1542 f1ts->setFieldNoProfileSBT(f2);
1545 f1ts->setFieldNoProfileSBT(f);
1546 f1ts->write(fileName,0);