1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDLoader.hxx"
21 #include "MEDLoaderBase.hxx"
22 #include "MEDFileUtilities.hxx"
23 #include "CellModel.hxx"
24 #include "MEDCouplingUMesh.hxx"
25 #include "MEDCouplingMemArray.hxx"
26 #include "MEDCouplingFieldDouble.hxx"
27 #include "MEDCouplingGaussLocalization.hxx"
28 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
30 #include "InterpKernelAutoPtr.hxx"
43 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
66 med_geometry_type typmainoeud[1] = { MED_NONE };
68 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
69 INTERP_KERNEL::NORM_SEG2,
70 INTERP_KERNEL::NORM_SEG3,
71 INTERP_KERNEL::NORM_SEG4,
72 INTERP_KERNEL::NORM_TRI3,
73 INTERP_KERNEL::NORM_QUAD4,
74 INTERP_KERNEL::NORM_TRI6,
75 INTERP_KERNEL::NORM_TRI7,
76 INTERP_KERNEL::NORM_QUAD8,
77 INTERP_KERNEL::NORM_QUAD9,
78 INTERP_KERNEL::NORM_TETRA4,
79 INTERP_KERNEL::NORM_PYRA5,
80 INTERP_KERNEL::NORM_PENTA6,
81 INTERP_KERNEL::NORM_HEXA8,
82 INTERP_KERNEL::NORM_HEXGP12,
83 INTERP_KERNEL::NORM_TETRA10,
84 INTERP_KERNEL::NORM_PYRA13,
85 INTERP_KERNEL::NORM_PENTA15,
86 INTERP_KERNEL::NORM_HEXA20,
87 INTERP_KERNEL::NORM_HEXA27,
88 INTERP_KERNEL::NORM_POLYGON,
89 INTERP_KERNEL::NORM_POLYHED };
91 med_geometry_type typmai3[34] = { MED_POINT1,//0
127 double MEDLoader::_EPS_FOR_NODE_COMP=1.e-12;
129 int MEDLoader::_COMP_FOR_CELL=0;
131 int MEDLoader::_TOO_LONG_STR=0;
133 using namespace ParaMEDMEM;
137 namespace MEDLoaderNS
139 class FieldPerTypeCopier
142 FieldPerTypeCopier(double *ptr):_ptr(ptr) { }
143 void operator()(const MEDLoader::MEDFieldDoublePerCellType& elt) { _ptr=std::copy(elt.getArray(),elt.getArray()+elt.getNbOfValues(),_ptr); }
151 ConnReaderML(const int *c, int val):_conn(c),_val(val) { }
152 bool operator() (const int& pos) { return _conn[pos]!=_val; }
158 std::vector<std::string> getMeshNamesFid(med_idt fid);
159 void readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName,
160 int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField,
161 std::list<MEDLoader::MEDFieldDoublePerCellType>& field,
162 double& time, std::vector<std::string>& infos);
163 std::vector<int> getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector<std::string>& fams);
164 std::vector<int> getIdsFromGroups(const char *fileName, const char *meshName, const std::vector<std::string>& grps);
165 med_int getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception);
166 void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity);
167 int readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector<int>& possibilities);
168 void readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn, std::string& desc);
169 int buildMEDSubConnectivityOfOneType(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families, INTERP_KERNEL::NormalizedCellType type,
170 std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
171 std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
172 MEDCouplingUMesh *readUMeshFromFileLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<int>& ids,
173 const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception);
174 void tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list<MEDLoader::MEDConnOfOneElemType>& medConnFrmt,
175 const std::vector<int>& familiesToKeep,
177 DataArrayInt* &connIndex,
179 ParaMEDMEM::DataArrayDouble *buildArrayFromRawData(const std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerType,
180 const std::vector<std::string>& infos);
181 int buildMEDSubConnectivityOfOneTypesPolyg(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
182 std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
183 int buildMEDSubConnectivityOfOneTypesPolyh(const std::vector<const DataArrayInt *>&conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
184 std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
185 std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
186 int buildMEDSubConnectivityOfOneTypeStaticTypes(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
187 INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
188 ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order,
189 ParaMEDMEM::TypeOfField typeOfOutField) throw(INTERP_KERNEL::Exception);
190 ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev2(const char *fileName, ParaMEDMEM::TypeOfField typeOfOutField, unsigned meshDim, const int *renumCell, const ParaMEDMEM::MEDCouplingUMesh *mesh,
191 const std::vector<std::string>& infos, const char *fieldName, int iteration, int order, double time,
192 std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerCellType) throw(INTERP_KERNEL::Exception);
193 med_idt appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, med_int& numdt, med_int& numo, med_float& dt);
194 void appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f);
195 void appendNodeProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshNodeIds);
196 void appendCellProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIds);
197 void appendNodeElementProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIds);
198 void prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *cellIds, std::list<MEDLoader::MEDFieldDoublePerCellType>& split);
199 void fillGaussDataOnField(const char *fileName, const std::list<MEDLoader::MEDFieldDoublePerCellType>& data, MEDCouplingFieldDouble *f);
200 void writeUMeshesDirectly(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& mesh, const std::vector<const DataArrayInt *>& families, bool forceFromScratch, bool &isRenumbering);
201 void writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool forceFromScratch);
202 void writeFieldAndMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch);
203 void writeFieldTryingToFitExistingMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f);
209 * 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.
211 void MEDLoader::setEpsilonForNodeComp(double val) throw(INTERP_KERNEL::Exception)
213 _EPS_FOR_NODE_COMP=val;
217 * 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.
219 void MEDLoader::setCompPolicyForCell(int val) throw(INTERP_KERNEL::Exception)
225 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
226 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
228 void MEDLoader::setTooLongStrPolicy(int val) throw(INTERP_KERNEL::Exception)
234 * @param lgth is the size of fam tab. For classical types conn is size of 'lgth'*number_of_nodes_in_type.
235 * @param index is optionnal only for polys. Set it to 0 if it is not the case.
236 * @param connLgth is the size of conn in the case of poly. Unsued if it is not the case.
238 MEDLoader::MEDConnOfOneElemType::MEDConnOfOneElemType(INTERP_KERNEL::NormalizedCellType type, int *conn, int *index, int *fam, int lgth, int connLgth):_lgth(lgth),_fam(fam),
239 _conn(conn),_index(index),
240 _global(0),_conn_lgth(connLgth),
245 void MEDLoader::MEDConnOfOneElemType::setGlobal(int *global)
255 void MEDLoader::MEDConnOfOneElemType::releaseArray()
263 MEDLoader::MEDFieldDoublePerCellType::MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int ntuple,
264 const int *cellIdPerType, const char *locName):_ntuple(ntuple),_ncomp(ncomp),_values(values),_type(type)
267 _cell_id_per_type.insert(_cell_id_per_type.end(),cellIdPerType,cellIdPerType+ntuple);
272 void MEDLoader::MEDFieldDoublePerCellType::releaseArray()
279 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
281 med_mesh_type type_maillage;
282 char maillage_description[MED_COMMENT_SIZE+1];
283 char dtunit[MED_COMMENT_SIZE+1];
286 char nommaa[MED_NAME_SIZE+1];
287 med_axis_type axistype;
288 med_sorting_type stype;
289 med_int n=MEDnMesh(fid);
290 std::vector<std::string> ret(n);
293 int naxis=MEDmeshnAxis(fid,i+1);
294 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
295 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
297 MEDmeshInfo(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit);
298 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
304 void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list<MEDLoader::MEDFieldDoublePerCellType>& data, MEDCouplingFieldDouble *f)
306 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
307 char locName[MED_NAME_SIZE+1];
308 int nloc=MEDnLocalization(fid);
309 med_geometry_type typeGeo;
310 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=data.begin();iter!=data.end();iter++)
312 const std::string& loc=(*iter).getLocName();
316 for(;idLoc<=nloc;idLoc++)
318 char geointerpname[MED_NAME_SIZE+1]="";
319 char ipointstructmeshname[MED_NAME_SIZE+1]="";
320 med_int nsectionmeshcell;
321 med_geometry_type sectiongeotype;
322 MEDlocalizationInfo(fid,idLoc,locName,&typeGeo,&spaceDim,&nbOfGaussPt, geointerpname, ipointstructmeshname, &nsectionmeshcell,
327 int dim=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getDimension();
328 int nbPtPerCell=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getNumberOfNodes();
329 std::vector<double> refcoo(nbPtPerCell*dim),gscoo(nbOfGaussPt*dim),w(nbOfGaussPt);
330 MEDlocalizationRd(fid,(*iter).getLocName().c_str(),MED_FULL_INTERLACE,&refcoo[0],&gscoo[0],&w[0]);
331 f->setGaussLocalizationOnType((*iter).getType(),refcoo,gscoo,w);
338 void MEDLoader::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception)
340 MEDFileUtilities::CheckFileForRead(fileName);
343 std::vector<std::string> MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception)
345 CheckFileForRead(fileName);
346 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
347 std::vector<std::string> ret=MEDLoaderNS::getMeshNamesFid(fid);
352 std::vector< std::pair<std::string,std::string> > MEDLoader::GetComponentsNamesOfField(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
354 CheckFileForRead(fileName);
355 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
356 med_int nbFields=MEDnField(fid);
357 std::vector<std::string> fields(nbFields);
358 med_field_type typcha;
359 for(int i=0;i<nbFields;i++)
361 med_int ncomp=MEDfieldnComponent(fid,i+1);
362 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
363 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
364 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
367 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
368 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
369 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
370 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
371 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
372 if(curFieldName==fieldName)
374 std::vector< std::pair<std::string,std::string> > ret(ncomp);
375 for(int j=0;j<ncomp;j++)
376 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
377 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
380 fields[i]=curFieldName;
382 std::ostringstream oss; oss << "MEDLoader::GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
383 oss << "Possible field names are : " << std::endl;
384 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
385 throw INTERP_KERNEL::Exception(oss.str().c_str());
389 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
390 * It returns, in this order :
391 * - 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...
392 * - the mesh dimension
393 * - the space dimension
394 * - the number of nodes
396 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > MEDLoader::GetUMeshGlobalInfo(const char *fileName, const char *meshName, int &meshDim, int& spaceDim, int& numberOfNodes) throw(INTERP_KERNEL::Exception)
398 CheckFileForRead(fileName);
399 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
401 char nommaa[MED_NAME_SIZE+1];
402 char maillage_description[MED_COMMENT_SIZE+1];
403 med_mesh_type type_maillage;
404 std::string trueMeshName;
405 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
406 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
407 med_sorting_type sortingType;
409 med_axis_type axisType;
410 int naxis=MEDmeshnAxis(fid,meshId);
411 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
412 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
413 MEDmeshInfo(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit);
414 if(type_maillage!=MED_UNSTRUCTURED_MESH)
416 std::ostringstream oss; oss << "MEDLoader::GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
417 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
418 throw INTERP_KERNEL::Exception(oss.str().c_str());
422 throw INTERP_KERNEL::Exception("MEDLoader::GetUMeshGlobalInfo : multisteps on mesh not managed !");
425 MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
427 std::vector<int> dims;
428 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
429 med_bool changement,transformation;
430 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
432 med_geometry_type curMedType=typmai[i];
433 int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
436 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
437 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
438 dims.push_back(mdimCell);
439 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
442 int maxLev=*std::max_element(dims.begin(),dims.end());
443 int lowLev=*std::min_element(dims.begin(),dims.end());
444 int nbOfLevels=maxLev-lowLev+1;
445 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
446 for(std::size_t i=0;i<dims.size();i++)
448 ret[maxLev-dims[i]].push_back(geoTypes[i]);
450 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
454 std::vector<std::string> MEDLoader::GetMeshNamesOnField(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
456 CheckFileForRead(fileName);
457 std::vector<std::string> ret;
459 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
460 med_int nbFields=MEDnField(fid);
462 med_field_type typcha;
463 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
464 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
467 for(int i=0;i<nbFields;i++)
469 med_int ncomp=MEDfieldnComponent(fid,i+1);
470 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
471 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
473 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
474 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
475 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
476 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
477 if(curFieldName==fieldName)
478 ret.push_back(meshName);
484 std::vector<std::string> MEDLoader::GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
486 CheckFileForRead(fileName);
487 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
488 med_int nfam=MEDnFamily(fid,meshName);
489 std::vector<std::string> ret(nfam);
490 char nomfam[MED_NAME_SIZE+1];
492 for(int i=0;i<nfam;i++)
494 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
495 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
496 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
497 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
498 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
499 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
500 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
501 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
509 std::vector<std::string> MEDLoader::GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception)
511 CheckFileForRead(fileName);
512 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
513 med_int nfam=MEDnFamily(fid,meshName);
514 std::vector<std::string> ret;
515 char nomfam[MED_NAME_SIZE+1];
517 for(int i=0;i<nfam;i++)
519 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
520 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
521 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
522 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
523 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
524 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
525 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
526 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
527 for(int j=0;j<ngro;j++)
529 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
538 std::vector<std::string> MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception)
540 CheckFileForRead(fileName);
541 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
542 med_int nfam=MEDnFamily(fid,meshName);
543 std::vector<std::string> ret;
544 char nomfam[MED_NAME_SIZE+1];
547 for(int i=0;i<nfam && !found;i++)
549 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
550 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
551 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
552 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
553 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
554 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
555 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
556 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
557 found=(cur==famName);
559 for(int j=0;j<ngro;j++)
561 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
568 std::ostringstream oss;
569 oss << "MEDLoader::GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
570 throw INTERP_KERNEL::Exception(oss.str().c_str());
576 std::vector<std::string> MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
578 CheckFileForRead(fileName);
579 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
580 med_int nfam=MEDnFamily(fid,meshName);
581 std::vector<std::string> ret;
582 char nomfam[MED_NAME_SIZE+1];
584 for(int i=0;i<nfam;i++)
586 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
587 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
588 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
589 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
590 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
591 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
592 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
593 for(int j=0;j<ngro;j++)
595 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
596 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
603 std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
605 CheckFileForRead(fileName);
606 std::vector<ParaMEDMEM::TypeOfField> ret;
607 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
608 med_int nbFields=MEDnField(fid);
610 med_field_type typcha;
611 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
612 med_int numdt=0,numo=0;
614 char pflname[MED_NAME_SIZE+1]="";
615 char locname[MED_NAME_SIZE+1]="";
616 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
617 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
620 for(int i=0;i<nbFields;i++)
622 med_int ncomp=MEDfieldnComponent(fid,i+1);
623 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
624 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
625 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
627 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
628 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
629 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
630 if(curMeshName==meshName)
632 if(curFieldName==fieldName)
638 for(int ii=0;ii<nbPdt && !found;ii++)
640 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
641 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
642 pflname,&profilesize,locname,&nbi);
645 ret.push_back(ON_NODES);
651 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
655 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
656 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
657 pflname,&profilesize,locname,&nbi);
661 ret.push_back(ON_CELLS);
674 std::vector<std::string> MEDLoader::GetAllFieldNames(const char *fileName) throw(INTERP_KERNEL::Exception)
676 CheckFileForRead(fileName);
677 std::vector<std::string> ret;
678 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
679 med_int nbFields=MEDnField(fid);
680 med_field_type typcha;
681 for(int i=0;i<nbFields;i++)
683 med_int ncomp=MEDfieldnComponent(fid,i+1);
684 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
685 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
686 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
687 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
688 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
691 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
692 ret.push_back(std::string(nomcha));
698 std::vector<std::string> MEDLoader::GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
700 CheckFileForRead(fileName);
701 std::vector<std::string> ret;
702 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
703 med_int nbFields=MEDnField(fid);
705 med_field_type typcha;
706 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
707 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
709 for(int i=0;i<nbFields;i++)
711 med_int ncomp=MEDfieldnComponent(fid,i+1);
712 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
713 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
714 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
717 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
718 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
719 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
721 if(curMeshName==meshName)
722 ret.push_back(curFieldName);
730 std::vector<std::string> MEDLoader::GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
732 CheckFileForRead(fileName);
736 return GetCellFieldNamesOnMesh(fileName,meshName);
738 return GetNodeFieldNamesOnMesh(fileName,meshName);
740 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
744 std::vector<std::string> MEDLoader::GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
746 CheckFileForRead(fileName);
747 std::vector<std::string> ret;
748 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
749 med_int nbFields=MEDnField(fid);
751 med_field_type typcha;
752 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
753 med_int numdt=0,numo=0;
755 char pflname[MED_NAME_SIZE+1]="";
756 char locname[MED_NAME_SIZE+1]="";
757 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
758 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
759 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
763 for(int i=0;i<nbFields;i++)
765 med_int ncomp=MEDfieldnComponent(fid,i+1);
766 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
767 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
768 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
769 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
770 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
772 if(curMeshName==meshName)
775 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
779 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
780 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
781 pflname,&profilesize,locname,&nbi);
785 ret.push_back(curFieldName);
795 std::vector<std::string> MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
797 CheckFileForRead(fileName);
798 std::vector<std::string> ret;
799 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
800 med_int nbFields=MEDnField(fid);
801 char pflname[MED_NAME_SIZE+1]="";
802 char locname[MED_NAME_SIZE+1]="";
804 med_field_type typcha;
805 med_int numdt=0,numo=0;
807 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
808 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
809 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
812 for(int i=0;i<nbFields;i++)
814 med_int ncomp=MEDfieldnComponent(fid,i+1);
815 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
816 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
818 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
819 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
820 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
824 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
825 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
826 pflname,&profilesize,locname,&nbi);
827 if(curMeshName==meshName && nbOfVal>0)
829 ret.push_back(curFieldName);
837 std::vector< std::pair< std::pair<int,int>, double> > MEDLoader::GetAllFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
839 CheckFileForRead(fileName);
840 std::string meshNameCpp(meshName);
841 std::vector< std::pair< std::pair<int,int>, double > > ret;
842 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
843 med_int nbFields=MEDnField(fid);
845 med_field_type typcha;
846 med_int numdt=0,numo=0;
848 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
849 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
850 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
853 for(int i=0;i<nbFields;i++)
855 med_int ncomp=MEDfieldnComponent(fid,i+1);
856 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
857 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
859 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
860 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
861 if(curFieldName==fieldName)
863 for(int k=0;k<nbPdt;k++)
865 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
866 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
874 double MEDLoader::GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
876 CheckFileForRead(fileName);
877 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
878 med_int nbFields=MEDnField(fid);
880 med_field_type typcha;
881 med_int numdt=0,numo=0;
884 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
885 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
886 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
890 double ret=std::numeric_limits<double>::max();
891 for(int i=0;i<nbFields && !found;i++)
893 med_int ncomp=MEDfieldnComponent(fid,i+1);
894 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
895 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
897 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt);
898 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
899 if(curFieldName==fieldName)
902 for(int k=0;k<nbPdt;k++)
904 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
905 if(numdt==iteration && numo==order)
914 if(!found || !found2)
916 std::ostringstream oss;
917 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
918 throw INTERP_KERNEL::Exception(oss.str().c_str());
923 std::vector< std::pair<int,int> > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
925 CheckFileForRead(fileName);
929 return GetCellFieldIterations(fileName,meshName,fieldName);
931 return GetNodeFieldIterations(fileName,meshName,fieldName);
933 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
937 std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
939 CheckFileForRead(fileName);
940 std::string meshNameCpp(meshName);
941 std::vector< std::pair<int,int> > ret;
942 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
943 med_int nbFields=MEDnField(fid);
945 med_field_type typcha;
946 med_int numdt=0,numo=0;
948 char pflname[MED_NAME_SIZE+1]="";
949 char locname[MED_NAME_SIZE+1]="";
950 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
951 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
952 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
955 for(int i=0;i<nbFields;i++)
957 med_int ncomp=MEDfieldnComponent(fid,i+1);
958 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
959 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
961 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
962 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
963 if(curFieldName==fieldName)
966 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
968 for(int k=0;k<nbPdt;k++)
971 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
972 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
973 pflname,&profilesize,locname,&nbi);
974 std::string maa_ass_cpp(maa_ass);
975 if(meshNameCpp==maa_ass_cpp && nbOfVal>0)
978 ret.push_back(std::make_pair(numdt,numo));
988 std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
990 CheckFileForRead(fileName);
991 std::string meshNameCpp(meshName);
992 std::vector< std::pair<int,int> > ret;
993 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
994 med_int nbFields=MEDnField(fid);
996 med_field_type typcha;
997 med_int numdt=0,numo=0;
999 char pflname[MED_NAME_SIZE+1]="";
1000 char locname[MED_NAME_SIZE+1]="";
1001 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1002 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
1003 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1006 for(int i=0;i<nbFields;i++)
1008 med_int ncomp=MEDfieldnComponent(fid,i+1);
1009 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
1010 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1012 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
1013 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1014 if(curFieldName==fieldName)
1016 for(int k=0;k<nbPdt;k++)
1018 int profilesize,nbi;
1019 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
1020 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1021 pflname,&profilesize,locname,&nbi);
1022 std::string maa_ass_cpp(maa_ass);
1023 if(meshNameCpp==maa_ass_cpp && nbOfVal>0)
1025 ret.push_back(std::make_pair(numdt,numo));
1035 * This method reads all the content of a field 'fieldName' at a time specified by (iteration,order) lying on a mesh 'meshName' with a specified type 'TypeOfOutField'
1036 * The returned values are strored in 'field' (sorted by type of cell), time corresponding to field, and 'infos' to load properly little strings.
1037 * The principle of this method is to put into 'field' only data that fulfills \b perfectly request.
1039 void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName,
1040 int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField,
1041 std::list<MEDLoader::MEDFieldDoublePerCellType>& field,
1042 double& time, std::vector<std::string>& infos)
1045 MEDFileUtilities::CheckFileForRead(fileName);
1046 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1047 med_int nbFields=MEDnField(fid);
1049 med_field_type typcha;
1050 char nomcha[MED_NAME_SIZE+1]="";
1051 char pflname [MED_NAME_SIZE+1]="";
1052 char locname [MED_NAME_SIZE+1]="";
1053 std::map<ParaMEDMEM::TypeOfField, med_entity_type> tabEnt;
1054 std::map<ParaMEDMEM::TypeOfField, med_geometry_type *> tabType;
1055 std::map<ParaMEDMEM::TypeOfField, int> tabTypeLgth;
1058 tabEnt[ON_CELLS]=MED_CELL;
1059 tabType[ON_CELLS]=typmai;
1060 tabTypeLgth[ON_CELLS]=MED_N_CELL_FIXED_GEO;
1061 tabEnt[ON_NODES]=MED_NODE;
1062 tabType[ON_NODES]=typmainoeud;
1063 tabTypeLgth[ON_NODES]=1;
1064 tabEnt[ON_GAUSS_PT]=MED_CELL;
1065 tabType[ON_GAUSS_PT]=typmai;
1066 tabTypeLgth[ON_GAUSS_PT]=MED_N_CELL_FIXED_GEO;
1067 tabEnt[ON_GAUSS_NE]=MED_NODE_ELEMENT;
1068 tabType[ON_GAUSS_NE]=typmai;
1069 tabTypeLgth[ON_GAUSS_NE]=MED_N_CELL_FIXED_GEO;
1071 for(int i=0;i<nbFields && !found;i++)
1073 med_int ncomp=MEDfieldnComponent(fid,i+1);
1074 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
1075 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1076 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
1077 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1079 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
1080 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
1081 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1082 found=(curFieldName==fieldName) && (curMeshName==meshName);
1085 infos.resize(ncomp);
1086 for(int ii=0;ii<ncomp;ii++)
1087 infos[ii]=MEDLoaderBase::buildUnionUnit(comp+ii*MED_SNAME_SIZE,MED_SNAME_SIZE,unit+ii*MED_SNAME_SIZE,MED_SNAME_SIZE);
1089 med_int numdt=0,numo=0;
1091 for(int k=0;k<nbPdt && !found2;k++)
1093 MEDfieldComputingStepInfo(fid,fieldName,k+1,&numdt,&numo,&dt);
1094 found2=(numdt==iteration && numo==order);
1100 std::ostringstream oss; oss << "FieldDouble in file \""<< fileName<< "\" with name \"" << fieldName << "\" on mesh \"" << meshName;
1101 oss << "\" does not have such time step : iteration=" << iteration << " order=" << order << std::endl;
1102 throw INTERP_KERNEL::Exception(oss.str().c_str());
1104 for(int j=0;j<tabTypeLgth[typeOfOutField];j++)
1108 int profilesize,nbi;
1109 int nval=MEDfieldnValueWithProfile(fid,fieldName,numdt,numo,tabEnt[typeOfOutField],tabType[typeOfOutField][j],1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi);
1112 double *valr=new double[ncomp*nval*nbi];
1113 MEDfieldValueWithProfileRd(fid,fieldName,iteration,order,tabEnt[typeOfOutField],tabType[typeOfOutField][j],MED_COMPACT_PFLMODE,
1114 pflname,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(unsigned char*)valr);
1115 std::string tmp(locname);
1116 if((locname[0]!='\0' && (typeOfOutField!=ON_GAUSS_PT))
1117 || (locname[0]=='\0' && typeOfOutField==ON_GAUSS_PT))
1122 INTERP_KERNEL::AutoPtr<int> pfl=0;
1123 if(pflname[0]!='\0')
1126 MEDprofileRd(fid,pflname,pfl);
1128 field.push_back(MEDLoader::MEDFieldDoublePerCellType(typmai2[j],valr,ncomp,nval*nbi,pfl,locname));
1136 std::ostringstream oss; oss << "MEDLoaderNS::readFieldDoubleDataInMedFile : no such couple meshName=\"" << meshName << "\", fieldName=\"" << fieldName << "\" in file \"" << fileName << "\" !";
1137 throw INTERP_KERNEL::Exception(oss.str().c_str());
1141 std::vector<int> MEDLoaderNS::getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector<std::string>& fams)
1143 std::vector<int> ret;
1144 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1145 med_int nfam=MEDnFamily(fid,meshName);
1146 char nomfam[MED_NAME_SIZE+1];
1148 for(int i=0;i<nfam;i++)
1150 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
1151 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
1152 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
1153 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
1154 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
1155 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
1156 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
1157 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
1158 if(std::find(fams.begin(),fams.end(),cur)!=fams.end())
1159 ret.push_back(numfam);
1165 std::vector<int> MEDLoaderNS::getIdsFromGroups(const char *fileName, const char *meshName, const std::vector<std::string>& grps)
1167 std::vector<int> ret;
1168 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1169 med_int nfam=MEDnFamily(fid,meshName);
1170 char nomfam[MED_NAME_SIZE+1];
1172 for(int i=0;i<nfam;i++)
1174 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
1175 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
1176 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
1177 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
1178 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
1179 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
1180 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
1181 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
1182 for(int j=0;j<ngro;j++)
1184 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
1185 if(std::find(grps.begin(),grps.end(),cur2)!=grps.end())
1187 ret.push_back(numfam);
1196 med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception)
1200 std::vector<std::string> meshes=getMeshNamesFid(fid);
1202 throw INTERP_KERNEL::Exception("No mesh in file");
1203 trueMeshName=meshes[0];
1206 std::string meshNameStr(meshName);
1207 std::vector<std::string> meshes=getMeshNamesFid(fid);
1209 throw INTERP_KERNEL::Exception("No mesh in file");
1210 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
1211 if(iter==meshes.end())
1213 std::ostringstream os2;
1214 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
1215 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
1216 throw INTERP_KERNEL::Exception(os2.str().c_str());
1218 trueMeshName=meshName;
1219 return iter-meshes.begin()+1;
1223 * This methods allows to merger all entities and to considerate only cell types.
1225 void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
1227 if(nbOfElemCell>=nbOfElemFace)
1229 whichEntity=MED_CELL;
1230 nbOfElem=nbOfElemCell;
1234 whichEntity=MED_CELL;
1235 nbOfElem=nbOfElemFace;
1240 * This method returns a first quick overview of mesh with name 'meshName' into the file 'fileName'.
1241 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
1242 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
1244 int MEDLoaderNS::readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector<int>& possibilities)
1246 possibilities.clear();
1247 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1250 char nommaa[MED_NAME_SIZE+1];
1251 char maillage_description[MED_COMMENT_SIZE+1];
1252 med_mesh_type type_maillage;
1254 std::string trueMeshName;
1255 med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
1256 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
1257 med_sorting_type sortingType;
1259 med_axis_type axisType;
1260 int naxis=MEDmeshnAxis(fid,meshId);
1261 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
1262 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
1263 MEDmeshInfo(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit);
1267 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
1269 med_int numdt,numit;
1271 MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
1273 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
1275 med_geometry_type curMedType=typmai[i];
1276 med_bool changement,transformation;
1277 int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
1278 int curNbOfElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);//limitation
1280 med_entity_type whichEntity;
1281 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
1284 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
1285 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
1286 poss.insert(curDim);
1293 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
1294 possibilities.push_back(*it-ret);
1301 void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn, std::string& description)
1303 char nommaa[MED_NAME_SIZE+1];
1304 char maillage_description[MED_COMMENT_SIZE+1];
1305 med_mesh_type type_maillage;
1308 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
1309 med_sorting_type sortingType;
1311 med_axis_type axisType;
1312 med_int numdt,numit;
1314 med_bool changement,transformation;
1316 Sdim=MEDmeshnAxis(fid,1);
1317 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(Sdim*MED_SNAME_SIZE);
1318 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(Sdim*MED_SNAME_SIZE);
1319 MEDmeshInfo(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,comp,unit);
1320 description=MEDLoaderBase::buildStringFromFortran(maillage_description,sizeof(maillage_description));
1321 MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
1322 int spaceDim=std::max((int)Mdim,(int)Sdim);
1323 int nCoords=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
1327 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
1329 coords=DataArrayDouble::New();
1330 coords->alloc(nCoords,spaceDim);
1331 double *coordsPtr=coords->getPointer();
1332 MEDmeshNodeCoordinateRd(fid,nommaa,numdt,numit,MED_FULL_INTERLACE,coordsPtr);
1333 for(int i=0;i<spaceDim;i++)
1335 std::string info=MEDLoaderBase::buildUnionUnit(comp+i*MED_SNAME_SIZE,MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
1336 coords->setInfoOnComponent(i,info.c_str());
1338 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
1340 med_geometry_type curMedType=typmai[i];
1341 med_entity_type whichEntity;
1342 int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
1343 int curNbOfElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);//limitation
1345 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
1348 int *connTab=new int[(curMedType%100)*curNbOfElem];
1349 int *fam=new int[curNbOfElem];
1350 MEDLoader::MEDConnOfOneElemType elem(typmai2[i],connTab,0,fam,curNbOfElem,-1);
1351 char *noms=new char[MED_SNAME_SIZE*curNbOfElem+1];
1352 med_bool withname=MED_FALSE,withnumber=MED_FALSE,withfam=MED_FALSE;
1353 int *globArr=new int[curNbOfElem];
1354 MEDmeshElementRd(fid,nommaa,numdt,numit,whichEntity,curMedType,MED_NODAL,MED_FULL_INTERLACE,connTab,&withname,noms,&withnumber,globArr,&withfam,fam);
1356 std::fill(fam,fam+curNbOfElem,0);
1358 //trying to read global numbering
1360 elem.setGlobal(globArr);
1363 //limitation manage withfam==false
1364 conn.push_back(elem);
1367 int curNbOfPolyElem;
1368 int curNbOfPolyElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1;
1369 int curNbOfPolyElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1;//limitation
1370 med_entity_type whichPolyEntity;
1371 MEDLoaderNS::dispatchElems(curNbOfPolyElemM,curNbOfPolyElemF,curNbOfPolyElem,whichPolyEntity);
1372 if(curNbOfPolyElem>0)
1374 med_int arraySize=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
1375 int *index=new int[curNbOfPolyElem+1];
1376 int *locConn=new int[arraySize];
1377 int *fam=new int[curNbOfPolyElem];
1378 int *globArr=new int[curNbOfPolyElem];
1379 MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYGON,locConn,index,fam,curNbOfPolyElem,arraySize);
1380 MEDmeshPolygonRd(fid,nommaa,numdt,numit,MED_CELL,MED_NODAL,index,locConn);
1381 if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
1383 if(MEDmeshEntityFamilyNumberRd(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,fam)!=0)
1384 std::fill(fam,fam+curNbOfPolyElem,0);
1387 std::fill(fam,fam+curNbOfPolyElem,0);
1388 if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
1390 if(MEDmeshEntityNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYGON,globArr)==0)
1391 elem.setGlobal(globArr);
1397 conn.push_back(elem);
1399 curNbOfPolyElem=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1;
1400 if(curNbOfPolyElem>0)
1402 med_int indexFaceLgth,connFaceLgth;
1403 indexFaceLgth=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation);
1404 connFaceLgth=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
1405 INTERP_KERNEL::AutoPtr<int> index=new int[curNbOfPolyElem+1];
1406 INTERP_KERNEL::AutoPtr<int> indexFace=new int[indexFaceLgth];
1407 INTERP_KERNEL::AutoPtr<int> locConn=new int[connFaceLgth];
1408 int *fam=new int[curNbOfPolyElem];
1409 int *globArr=new int[curNbOfPolyElem];
1410 MEDmeshPolyhedronRd(fid,nommaa,numdt,numit,MED_CELL,MED_NODAL,index,indexFace,locConn);
1411 if(MEDmeshnEntity(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
1413 if(MEDmeshEntityFamilyNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,fam)!=0)
1414 std::fill(fam,fam+curNbOfPolyElem,0);
1417 std::fill(fam,fam+curNbOfPolyElem,0);
1418 int arraySize=connFaceLgth;
1419 for(int i=0;i<curNbOfPolyElem;i++)
1420 arraySize+=index[i+1]-index[i]-1;
1421 int *finalConn=new int[arraySize];
1422 int *finalIndex=new int[curNbOfPolyElem+1];
1424 int *wFinalConn=finalConn;
1425 for(int i=0;i<curNbOfPolyElem;i++)
1427 finalIndex[i+1]=finalIndex[i]+index[i+1]-index[i]-1+indexFace[index[i+1]-1]-indexFace[index[i]-1];
1428 wFinalConn=std::copy(locConn+indexFace[index[i]-1]-1,locConn+indexFace[index[i]]-1,wFinalConn);
1429 for(int j=index[i];j<index[i+1]-1;j++)
1432 wFinalConn=std::copy(locConn+indexFace[j]-1,locConn+indexFace[j+1]-1,wFinalConn);
1435 MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYHED,finalConn,finalIndex,fam,curNbOfPolyElem,arraySize);
1436 if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
1438 if(MEDmeshEntityNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,globArr)==0)
1439 elem.setGlobal(globArr);
1445 conn.push_back(elem);
1451 namespace MEDLoaderNS
1454 unsigned calculateHighestMeshDim(const std::list<T>& conn)
1457 for(typename std::list<T>::const_iterator iter=conn.begin();iter!=conn.end();iter++)
1459 unsigned curDim=INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getDimension();
1467 void keepSpecifiedMeshDim(typename std::list<T>& conn, unsigned meshDim)
1469 for(typename std::list<T>::iterator iter=conn.begin();iter!=conn.end();)
1471 unsigned curDim=INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getDimension();
1474 (*iter).releaseArray();
1475 iter=conn.erase(iter);
1483 void keepTypes(typename std::list<T>& conn, const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep)
1485 if(!typesToKeep.empty())
1487 for(typename std::list<T>::iterator iter=conn.begin();iter!=conn.end();)
1489 INTERP_KERNEL::NormalizedCellType curType=(*iter).getType();
1490 if(std::find(typesToKeep.begin(),typesToKeep.end(),curType)==typesToKeep.end())
1492 (*iter).releaseArray();
1493 iter=conn.erase(iter);
1502 class FieldPerTypeAccumulator
1505 int operator()(int res, const MEDLoader::MEDFieldDoublePerCellType& elt) { return res+elt.getNbOfTuple(); }
1508 ParaMEDMEM::DataArrayDouble *MEDLoaderNS::buildArrayFromRawData(const std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerType,
1509 const std::vector<std::string>& infos)
1511 ParaMEDMEM::DataArrayDouble *ret=ParaMEDMEM::DataArrayDouble::New();
1512 int totalNbOfTuple=std::accumulate(fieldPerType.begin(),fieldPerType.end(),0,FieldPerTypeAccumulator());
1513 int nbOfComp=(*fieldPerType.begin()).getNbComp();
1514 double *ptr=new double[nbOfComp*totalNbOfTuple];
1515 ret->useArray(ptr,true,ParaMEDMEM::CPP_DEALLOC,totalNbOfTuple,nbOfComp);
1516 std::for_each(fieldPerType.begin(),fieldPerType.end(),FieldPerTypeCopier(ptr));
1517 for(int i=0;i<nbOfComp;i++)
1518 ret->setInfoOnComponent(i,infos[i].c_str());
1522 class PolyCounterForFams
1525 PolyCounterForFams(int id, const int *index):_id(id),_index(index),_count(0),_sigma(0) { }
1526 void operator()(int val) { if(val==_id) _sigma+=_index[_count+1]-_index[_count]; _count++; }
1527 int getSigma() const { return _sigma; }
1536 * This method fills unstructured connectivity using basic MED file format 'medConnFrmt'.
1537 * If in each elements of 'medConnFrmt' a renumbering cell array is found the aggregate array 'cellRenum' is returned.
1539 void MEDLoaderNS::tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list<MEDLoader::MEDConnOfOneElemType>& medConnFrmt,
1540 const std::vector<int>& familiesToKeep,
1541 DataArrayInt* &conn,
1542 DataArrayInt* &connIndex,
1545 bool keepAll=familiesToKeep.empty();
1546 if(medConnFrmt.empty())
1553 std::list<MEDLoader::MEDConnOfOneElemType>::const_iterator iter=medConnFrmt.begin();
1554 int totalNbOfCells=0;
1555 int totalNbOfMedConn=0;
1558 for(;iter!=medConnFrmt.end();iter++)
1560 if((*iter).getGlobal()==0)
1562 const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::GetCellModel((*iter).getType());
1564 totalNbOfCells+=(*iter).getLength();
1566 for(std::vector<int>::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++)
1567 totalNbOfCells+=std::count((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),*iter2);
1568 if(!cellMod.isDynamic())
1570 totalNbOfMedConn+=(*iter).getLength()*cellMod.getNumberOfNodes();
1572 for(std::vector<int>::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++)
1573 totalNbOfMedConn+=std::count((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),*iter2)*cellMod.getNumberOfNodes();
1576 totalNbOfMedConn+=(*iter).getConnLength();
1578 for(std::vector<int>::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++)
1580 PolyCounterForFams res=std::for_each((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),PolyCounterForFams(*iter2,(*iter).getIndex()));
1581 totalNbOfMedConn+=res.getSigma();
1584 connIndex=DataArrayInt::New();
1585 conn=DataArrayInt::New();
1586 connIndex->alloc(totalNbOfCells+1,1);
1587 int *connIdxPtr=connIndex->getPointer();
1589 conn->alloc(totalNbOfMedConn+totalNbOfCells,1);
1590 int *connPtr=conn->getPointer();
1592 cellRenum=new int[totalNbOfCells];
1593 int *renumW=cellRenum;
1594 for(iter=medConnFrmt.begin();iter!=medConnFrmt.end();iter++)
1596 INTERP_KERNEL::NormalizedCellType type=(*iter).getType();
1597 const int *sourceConn=(*iter).getArray();
1598 const int *sourceIndex=(*iter).getIndex();
1599 const int *globalNum=(*iter).getGlobal();
1600 const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::GetCellModel(type);
1601 int nbOfCellsInCurType;
1602 int nbOfNodesIn1Cell=cellMod.getNumberOfNodes();
1603 nbOfCellsInCurType=(*iter).getLength();
1604 bool isDyn=cellMod.isDynamic();
1606 for(int i=0;i<nbOfCellsInCurType;i++)
1609 {//duplication of next 3 lines needed.
1610 *connIdxPtr=connFillId;
1613 *renumW++=globalNum[i];
1615 tmpConnPtr=std::transform(sourceConn,sourceConn+nbOfNodesIn1Cell,connPtr,std::bind2nd(std::minus<int>(),1));
1617 tmpConnPtr=std::transform(sourceConn,sourceConn+sourceIndex[i+1]-sourceIndex[i],connPtr,std::bind2nd(std::minus<int>(),1));
1619 nbOfNodesIn1Cell=tmpConnPtr-connPtr;
1620 connFillId+=nbOfNodesIn1Cell+1;
1623 else if(std::find(familiesToKeep.begin(),familiesToKeep.end(),(*iter).getFam()[i])!=familiesToKeep.end())
1624 {//duplication of next 3 lines needed.
1625 *connIdxPtr=connFillId;
1628 *renumW++=globalNum[i];
1630 tmpConnPtr=std::transform(sourceConn,sourceConn+nbOfNodesIn1Cell,connPtr,std::bind2nd(std::minus<int>(),1));
1631 else//The duplication of code is motivated by the line underneath.
1632 tmpConnPtr=std::transform((*iter).getArray()+sourceIndex[i]-1,(*iter).getArray()+sourceIndex[i+1]-1,connPtr,std::bind2nd(std::minus<int>(),1));
1634 nbOfNodesIn1Cell=tmpConnPtr-connPtr;
1635 connFillId+=nbOfNodesIn1Cell+1;
1638 sourceConn+=nbOfNodesIn1Cell;
1640 *connIdxPtr=connFillId;
1644 namespace MEDLoaderNS
1647 void releaseMEDFileCoreFrmt(typename std::list<T>& medConnFrmt)
1649 for(typename std::list<T>::iterator iter=medConnFrmt.begin();iter!=medConnFrmt.end();iter++)
1650 (*iter).releaseArray();
1651 medConnFrmt.clear();
1656 * This method builds a sub set of connectivity for a given type 'type'. \b WARNING connV,connVIndex and familiesV must have same size !
1657 * @param connV input containing connectivity with MEDCoupling format.
1658 * @param connVIndex input containing connectivity index in MEDCoupling format.
1659 * @param familiesV input that may be equal to 0. This specifies an array specifying cell family foreach cell.
1660 * @param type input specifying which cell types will be extracted in conn4MEDFile.
1661 * @param conn4MEDFile output containing the connectivity directly understandable by MEDFile; conn4MEDFile has to be empty before this method called.
1662 * @param connIndex4MEDFile output containing index connectivity understandable by MEDFile; only used by polygons and polyhedrons (it is face nodal connec).
1663 * @param connIndexRk24MEDFile output containing index of rank 2 understandable by MEDFile; only used by polyhedrons.
1664 * @param fam4MEDFile output containing family number of cells whose type is 'type'. This output is updated only if 'families' is different than 0.
1665 * @return nb of elements extracted.
1667 int MEDLoaderNS::buildMEDSubConnectivityOfOneTypeStaticTypes(const std::vector<const DataArrayInt *>& connV, const std::vector<const DataArrayInt *>& connVIndex, const std::vector<const DataArrayInt *>& familiesV,
1668 INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
1671 int nbOfMeshes=connV.size();
1673 for(int i=0;i<nbOfMeshes;i++)
1675 const DataArrayInt *conn=connV[i];
1676 const DataArrayInt *connIndex=connVIndex[i];
1677 const DataArrayInt *families=familiesV[i];
1678 int nbOfElem=connIndex->getNbOfElems()-1;
1679 const int *connPtr=conn->getConstPointer();
1680 const int *connIdxPtr=connIndex->getConstPointer();
1681 const int *famPtr=0;
1683 famPtr=families->getConstPointer();
1684 for(int ii=0;ii<nbOfElem;ii++)
1686 int delta=connIdxPtr[1]-connIdxPtr[0];
1689 conn4MEDFile.insert(conn4MEDFile.end(),connPtr+1,connPtr+delta);
1691 fam4MEDFile.push_back(famPtr[ii]);
1692 renumber.push_back(ii+1+renumOffset);
1698 renumOffset+=nbOfElem;
1700 std::transform(conn4MEDFile.begin(),conn4MEDFile.end(),conn4MEDFile.begin(),std::bind2nd(std::plus<int>(),1));
1704 int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyg(const std::vector<const DataArrayInt *>&connV, const std::vector<const DataArrayInt *>& connVIndex, const std::vector<const DataArrayInt *>& familiesV,
1705 std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
1708 int nbOfMeshes=connV.size();
1709 connIndex4MEDFile.push_back(1);
1711 for(int i=0;i<nbOfMeshes;i++)
1713 const DataArrayInt *conn=connV[i];
1714 const DataArrayInt *connIndex=connVIndex[i];
1715 const DataArrayInt *families=familiesV[i];
1716 int nbOfElem=connIndex->getNbOfElems()-1;
1717 const int *connPtr=conn->getConstPointer();
1718 const int *connIdxPtr=connIndex->getConstPointer();
1719 const int *famPtr=0;
1721 famPtr=families->getConstPointer();
1722 for(int ii=0;ii<nbOfElem;ii++)
1724 int delta=connIdxPtr[1]-connIdxPtr[0];
1725 if(*connPtr==INTERP_KERNEL::NORM_POLYGON)
1727 conn4MEDFile.insert(conn4MEDFile.end(),connPtr+1,connPtr+delta);
1728 connIndex4MEDFile.push_back(connIndex4MEDFile.back()+delta-1);
1730 fam4MEDFile.push_back(famPtr[ii]);
1731 renumber.push_back(ii+1+renumOffset);
1737 renumOffset+=nbOfElem;
1739 std::transform(conn4MEDFile.begin(),conn4MEDFile.end(),conn4MEDFile.begin(),std::bind2nd(std::plus<int>(),1));
1743 int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyh(const std::vector<const DataArrayInt *>& connV, const std::vector<const DataArrayInt *>& connVIndex, const std::vector<const DataArrayInt *>& familiesV,
1744 std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
1745 std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
1748 int nbOfMeshes=connV.size();
1749 connIndexRk24MEDFile.push_back(1);
1750 connIndex4MEDFile.push_back(1);
1752 for(int i=0;i<nbOfMeshes;i++)
1754 const DataArrayInt *conn=connV[i];
1755 const DataArrayInt *connIndex=connVIndex[i];
1756 const DataArrayInt *families=familiesV[i];
1757 int nbOfElem=connIndex->getNbOfElems()-1;
1758 const int *connPtr=conn->getConstPointer();
1759 const int *connIdxPtr=connIndex->getConstPointer();
1760 const int *famPtr=0;
1762 famPtr=families->getConstPointer();
1763 for(int ii=0;ii<nbOfElem;ii++)
1765 int delta=connIdxPtr[1]-connIdxPtr[0];
1766 if(*connPtr==INTERP_KERNEL::NORM_POLYHED)
1768 int nbOfFacesOfPolyh=std::count(connPtr+1,connPtr+delta,-1)+1;
1769 const int *work=connPtr+1;
1770 while(work!=connPtr+delta)
1772 const int *end=std::find(work,connPtr+delta,-1);
1773 conn4MEDFile.insert(conn4MEDFile.end(),work,end);
1774 connIndex4MEDFile.push_back(connIndex4MEDFile.back()+std::distance(work,end));
1775 if(end==connPtr+delta)
1780 connIndexRk24MEDFile.push_back(connIndexRk24MEDFile.back()+nbOfFacesOfPolyh);
1782 fam4MEDFile.push_back(famPtr[ii]);
1783 renumber.push_back(ii+1+renumOffset);
1789 renumOffset+=nbOfElem;
1791 std::transform(conn4MEDFile.begin(),conn4MEDFile.end(),conn4MEDFile.begin(),std::bind2nd(std::plus<int>(),1));
1796 * This method builds a sub set of connectivity for a given type 'type'.
1797 * @param conn input containing connectivity with MEDCoupling format.
1798 * @param connIndex input containing connectivity index in MEDCoupling format.
1799 * @param families input containing, if any, the family number of each cells
1800 * @param type input specifying which cell types will be extracted in conn4MEDFile.
1801 * @param conn4MEDFile output containing the connectivity directly understandable by MEDFile; conn4MEDFile has to be empty before this method called.
1802 * @param connIndex4MEDFile output containing index connectivity understandable by MEDFile; only used by polygons and polyhedrons (it is face nodal connec).
1803 * @param connIndexRk24MEDFile output containing index of rank 2 understandable by MEDFile; only used by polyhedrons.
1804 * @param fam4MEDFile output containing families id of cells whose type is 'type'.
1805 * @return nb of elements extracted.
1807 int MEDLoaderNS::buildMEDSubConnectivityOfOneType(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
1808 INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile,
1809 std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
1812 const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::GetCellModel(type);
1813 if(!cellMod.isDynamic())
1814 return buildMEDSubConnectivityOfOneTypeStaticTypes(conn,connIndex,families,type,conn4MEDFile,fam4MEDFile,renumber);
1817 if(type==INTERP_KERNEL::NORM_POLYGON)
1818 return buildMEDSubConnectivityOfOneTypesPolyg(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,fam4MEDFile,renumber);
1820 return buildMEDSubConnectivityOfOneTypesPolyh(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,connIndexRk24MEDFile,fam4MEDFile,renumber);
1825 * @param ids is a in vector containing families ids whose cells have to be kept. If empty all cells are kept.
1826 * @param typesToKeep is a in vector that indicates which types to keep after dimension filtering.
1827 * @param meshDimExtract out parameter that gives the mesh dimension.
1828 * @param cellRenum out parameter that specifies the renumbering (if !=0) of cells in file.
1830 MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<int>& ids,
1831 const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception)
1833 if(meshDimRelToMax>0)
1834 throw INTERP_KERNEL::Exception("meshDimRelToMax must be <=0 !");
1835 //Extraction data from MED file.
1836 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1837 std::string trueMeshName;
1838 med_int mid=getIdFromMeshName(fid,meshName,trueMeshName);
1839 DataArrayDouble *coords=0;
1840 std::list<MEDLoader::MEDConnOfOneElemType> conn;
1842 readUMeshDataInMedFile(fid,mid,coords,conn,descr);
1843 meshDimExtract=MEDLoaderNS::calculateHighestMeshDim<MEDLoader::MEDConnOfOneElemType>(conn);
1844 meshDimExtract=meshDimExtract+meshDimRelToMax;
1845 MEDLoaderNS::keepSpecifiedMeshDim<MEDLoader::MEDConnOfOneElemType>(conn,meshDimExtract);
1846 MEDLoaderNS::keepTypes<MEDLoader::MEDConnOfOneElemType>(conn,typesToKeep);
1848 //Put data in returned data structure.
1849 MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
1850 ret->setName(trueMeshName.c_str());
1851 ret->setDescription(descr.c_str());
1852 ret->setMeshDimension(meshDimExtract);
1854 ret->setCoords(coords);
1857 DataArrayInt *connArr,*connIndexArr;
1858 tradMEDFileCoreFrmt2MEDCouplingUMesh(conn,ids,connArr,connIndexArr,cellRenum);
1859 ret->setConnectivity(connArr,connIndexArr);
1864 connIndexArr->decrRef();
1865 releaseMEDFileCoreFrmt<MEDLoader::MEDConnOfOneElemType>(conn);
1869 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char *fileName, ParaMEDMEM::TypeOfField typeOfOutField, unsigned meshDim, const int *cellRenum, const ParaMEDMEM::MEDCouplingUMesh *mesh,
1870 const std::vector<std::string>& infos, const char *fieldName, int iteration, int order, double time,
1871 std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerCellType) throw(INTERP_KERNEL::Exception)
1873 if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
1874 MEDLoaderNS::keepSpecifiedMeshDim<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType,meshDim);
1875 if(fieldPerCellType.empty())
1877 std::ostringstream oss; oss << "Error on reading file \"" << fileName << "\" meshName=\"" << mesh->getName();
1878 oss << std::endl << "FieldName=\"" << fieldName << "\" (iteration=" << iteration << ",order=" << order << ")" << std::endl;
1879 if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
1880 oss << "Request for cell field, maybe it is an ON_NODES field ?";
1882 oss << "Request for a node field, maybe it is an ON_CELLS field ?";
1883 throw INTERP_KERNEL::Exception(oss.str().c_str());
1886 ParaMEDMEM::MEDCouplingUMesh *newMesh=0;
1887 std::string mName(mesh->getName());
1888 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
1890 const std::vector<int>& cellIds=(*iter).getCellIdPerType();
1891 if(!cellIds.empty())
1893 std::vector<int> ci(cellIds.size());
1894 std::transform(cellIds.begin(),cellIds.end(),ci.begin(),std::bind2nd(std::plus<int>(),-1));
1895 ParaMEDMEM::MEDCouplingUMesh *mesh2=0;
1896 if(typeOfOutField==ON_CELLS)
1899 mesh2=newMesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size());
1901 mesh2=mesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size());
1903 else if(typeOfOutField==ON_NODES)
1905 DataArrayInt *da=0,*da2=0;
1908 if((int)ci.size()!=newMesh->getNumberOfNodes())
1910 da=newMesh->getCellIdsFullyIncludedInNodeIds(&ci[0],&ci[ci.size()]);
1911 mesh2=dynamic_cast<MEDCouplingUMesh *>(newMesh->buildPartAndReduceNodes(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems(),da2));
1916 if((int)ci.size()!=mesh->getNumberOfNodes())
1918 da=mesh->getCellIdsFullyIncludedInNodeIds(&ci[0],&ci[ci.size()]);
1919 mesh2=dynamic_cast<MEDCouplingUMesh *>(mesh->buildPartAndReduceNodes(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems(),da2));
1921 int nnodes=mesh2->getNumberOfNodes();
1922 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=DataArrayInt::New();
1923 const int *da2Ptr=da2->getConstPointer();
1924 da3->alloc(nnodes,1);
1925 int *da3Ptr=da3->getPointer();
1926 for(int i=0;i<(int)ci.size();i++)
1928 int val=da2Ptr[ci[i]];
1932 mesh2->renumberNodes(da3->getConstPointer(),nnodes);
1936 mesh2=mesh->clone(true);
1937 da=DataArrayInt::New();
1938 da->alloc((int)ci.size(),1);
1939 std::copy(ci.begin(),ci.end(),da->getPointer());
1940 da2=da->invertArrayO2N2N2O(ci.size());
1941 mesh2->renumberNodes(da2->getConstPointer(),(int)ci.size());
1955 ParaMEDMEM::MEDCouplingFieldDouble *ret=ParaMEDMEM::MEDCouplingFieldDouble::New(typeOfOutField,ONE_TIME);
1956 ret->setName(fieldName);
1957 ret->setTime(time,iteration,order);
1960 newMesh->setName(mName.c_str());//retrieving mesh name to avoid renaming due to mesh restriction in case of profile.
1961 ret->setMesh(newMesh);
1966 ParaMEDMEM::DataArrayDouble *arr=buildArrayFromRawData(fieldPerCellType,infos);
1970 if(typeOfOutField==ON_GAUSS_PT)
1971 fillGaussDataOnField(fileName,fieldPerCellType,ret);
1973 ret->renumberCellsWithoutMesh(cellRenum,true);
1977 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order,
1978 ParaMEDMEM::TypeOfField typeOfOutField) throw(INTERP_KERNEL::Exception)
1980 std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType;
1982 std::vector<std::string> infos;
1983 readFieldDoubleDataInMedFile(fileName,meshName,fieldName,iteration,order,typeOfOutField,fieldPerCellType,time,infos);
1984 std::vector<int> familiesToKeep;
1985 std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1986 if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
1987 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
1988 typesToKeep.push_back((*iter).getType());
1991 if(fieldPerCellType.empty())
1993 std::ostringstream oss; oss << "Error on reading file \"" << fileName << "\" meshName=\"" << meshName << "\" meshDimRelToMax=" << meshDimRelToMax;
1994 oss << std::endl << "FieldName=\"" << fieldName << "\" (iteration=" << iteration << ",order=" << order << ")" << std::endl;
1995 if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
1996 oss << "Request for cell field, maybe it is a node instead or by changing meshDimRelToMax ?";
1998 oss << "Request for a node field, maybe it is a cell field instead ?";
1999 throw INTERP_KERNEL::Exception(oss.str().c_str());
2001 MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingUMesh> mesh=readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
2002 ParaMEDMEM::MEDCouplingFieldDouble *ret=readFieldDoubleLev2(fileName,typeOfOutField,meshDim,cellRenum,mesh,infos,fieldName,iteration,order,time,fieldPerCellType);
2004 mesh->renumberCells(cellRenum,true);
2006 delete [] cellRenum;
2007 releaseMEDFileCoreFrmt<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType);
2013 MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
2015 CheckFileForRead(fileName);
2016 std::vector<int> familiesToKeep;
2017 std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2020 ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
2023 ret->renumberCells(cellRenum,true);
2024 delete [] cellRenum;
2029 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
2031 CheckFileForRead(fileName);
2032 std::vector<int> familiesToKeep;
2033 std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2036 ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,0,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
2039 ret->renumberCells(cellRenum,true);
2040 delete [] cellRenum;
2045 int MEDLoader::ReadUMeshDimFromFile(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
2047 CheckFileForRead(fileName);
2048 std::vector<int> poss;
2049 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
2052 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception)
2054 CheckFileForRead(fileName);
2055 std::vector<int> familiesToKeep=MEDLoaderNS::getIdsFromFamilies(fileName,meshName,fams);
2056 std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2059 ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
2061 ret->setName(fams.back().c_str());
2064 ret->renumberCells(cellRenum,true);
2065 delete [] cellRenum;
2070 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception)
2072 CheckFileForRead(fileName);
2073 std::vector<int> familiesToKeep=MEDLoaderNS::getIdsFromGroups(fileName,meshName,grps);
2074 std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2077 ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
2079 ret->setName(grps.back().c_str());
2082 ret->renumberCells(cellRenum,true);
2083 delete [] cellRenum;
2088 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadField(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
2090 CheckFileForRead(fileName);
2094 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
2096 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
2098 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
2100 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
2102 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
2106 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsOnSameMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
2107 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
2110 return std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>();
2111 CheckFileForRead(fileName);
2112 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> ret(its.size());
2115 //Retrieving mesh of rank 0 and field on rank 0 too.
2116 std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType;
2118 std::vector<std::string> infos;
2119 MEDLoaderNS::readFieldDoubleDataInMedFile(fileName,meshName,fieldName,its[0].first,its[0].second,type,fieldPerCellType,time,infos);
2120 std::vector<int> familiesToKeep;
2121 std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2122 if(type==ON_CELLS || type==ON_GAUSS_PT || type==ON_GAUSS_NE)
2123 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
2124 typesToKeep.push_back((*iter).getType());
2127 MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingUMesh> m1=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
2128 ret[0]=MEDLoaderNS::readFieldDoubleLev2(fileName,type,meshDim,cellRenum,m1,infos,fieldName,its[0].first,its[0].second,time,fieldPerCellType);
2130 m1->renumberCells(cellRenum,true);
2131 MEDLoaderNS::releaseMEDFileCoreFrmt<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType);
2133 for(int itId=1;itId<(int)its.size();itId++)
2135 std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType2;
2137 std::vector<std::string> infoss;
2138 MEDLoaderNS::readFieldDoubleDataInMedFile(fileName,meshName,fieldName,its[itId].first,its[itId].second,type,fieldPerCellType2,timmee,infoss);
2139 ret[itId]=MEDLoaderNS::readFieldDoubleLev2(fileName,type,meshDim,cellRenum,m1,infoss,fieldName,its[itId].first,its[itId].second,timmee,fieldPerCellType2);
2141 MEDLoaderNS::releaseMEDFileCoreFrmt<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType2);
2143 delete [] cellRenum;
2147 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsCellOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
2148 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
2150 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
2153 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsNodeOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
2154 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
2156 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
2159 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
2160 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
2162 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
2165 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussNEOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
2166 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
2168 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
2171 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
2173 return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_CELLS);
2176 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
2178 return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_NODES);
2181 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
2183 return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_GAUSS_PT);
2186 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
2188 return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_GAUSS_NE);
2192 * @param families input parameter that specifies the field on int on each cells of 'mesh'.
2193 * @param isRenumbering output parameter that specifies if a renumbering of mesh has been needed.
2195 void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& mesh, const std::vector<const DataArrayInt *>& families, bool forceFromScratch, bool &isRenumbering)
2197 med_idt fid=MEDfileOpen(fileName,forceFromScratch?MED_ACC_CREAT:MED_ACC_RDWR);
2198 std::string meshName(mesh[0]->getName());
2202 throw INTERP_KERNEL::Exception("MEDCouplingMesh must have a not null name !");
2204 isRenumbering=false;
2205 bool isFamilies=true;
2206 std::vector<const DataArrayInt *> conn;
2207 std::vector<const DataArrayInt *> connIndex;
2208 std::set<INTERP_KERNEL::NormalizedCellType> allTypes;
2209 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=mesh.begin();iter!=mesh.end();iter++)
2211 isRenumbering|=!(*iter)->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
2212 isFamilies&=(families[std::distance(mesh.begin(),iter)]!=0);
2213 conn.push_back((*iter)->getNodalConnectivity());
2214 connIndex.push_back((*iter)->getNodalConnectivityIndex());
2215 const std::set<INTERP_KERNEL::NormalizedCellType>& curTypes=(*iter)->getAllTypes();
2216 allTypes.insert(curTypes.begin(),curTypes.end());
2218 INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2219 INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
2220 MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_NAME_SIZE,maa,MEDLoader::_TOO_LONG_STR);
2221 MEDLoaderBase::safeStrCpy(mesh[0]->getDescription(),MED_COMMENT_SIZE,desc,MEDLoader::_TOO_LONG_STR);
2222 const int spaceDim=mesh[0]->getSpaceDimension();
2223 const int meshDim=mesh[0]->getMeshDimension();
2224 const DataArrayDouble *arr=mesh[0]->getCoords();
2225 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
2226 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
2227 for(int i=0;i<spaceDim;i++)
2229 std::string info=arr->getInfoOnComponent(i);
2231 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
2232 MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
2233 MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
2235 MEDmeshCr(fid,maa,spaceDim,meshDim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
2236 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=mesh.begin();iter!=mesh.end();iter++)
2238 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2240 med_geometry_type curMedType=typmai[i];
2241 INTERP_KERNEL::NormalizedCellType curType=typmai2[i];
2242 if(allTypes.find(curType)!=allTypes.end())
2244 std::vector<int> medConn;
2245 std::vector<int> medConnIndex;
2246 std::vector<int> medConnIndex2;
2247 std::vector<int> fam;
2248 std::vector<int> renumber;
2249 int nbOfElt=MEDLoaderNS::buildMEDSubConnectivityOfOneType(conn,connIndex,families,curType,medConn,medConnIndex,medConnIndex2,fam,renumber);
2250 if(curMedType!=MED_POLYGON && curMedType!=MED_POLYHEDRON)
2251 MEDmeshElementConnectivityWr(fid,maa,-1,-1,0.,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,nbOfElt,&medConn[0]);
2254 if(curMedType==MED_POLYGON)
2255 MEDmeshPolygonWr(fid,maa,-1,-1,0.,MED_CELL,MED_NODAL,medConnIndex.size(),&medConnIndex[0],&medConn[0]);
2256 if(curMedType==MED_POLYHEDRON)
2258 MEDmeshPolyhedronWr(fid,maa,-1,-1,0.,MED_CELL,MED_NODAL,medConnIndex2.size(),&medConnIndex2[0],medConnIndex.size(),&medConnIndex[0],
2263 MEDmeshEntityFamilyNumberWr(fid,maa,-1,-1,MED_CELL,curMedType,nbOfElt,&fam[0]);
2265 MEDmeshEntityNumberWr(fid,maa,-1,-1,MED_CELL,curMedType,nbOfElt,&renumber[0]);
2269 char familyName[MED_NAME_SIZE+1];
2270 std::fill(familyName,familyName+MED_NAME_SIZE+1,'\0');
2271 const char DftFamilyName[]="DftFamily";
2272 std::copy(DftFamilyName,DftFamilyName+sizeof(DftFamilyName),familyName);
2273 MEDfamilyCr(fid,maa,familyName,0,0,0);
2275 MEDmeshNodeCoordinateWr(fid,maa,-1,-1,0.,MED_FULL_INTERLACE,mesh[0]->getNumberOfNodes(),arr->getConstPointer());
2280 * In this method meshes are assumed to shared the same coords.
2281 * This method makes the assumption that 'meshes' is not empty, no check on that is done (responsability of the caller)
2283 void MEDLoaderNS::writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool forceFromScratch)
2285 std::string meshNameCpp(meshName);
2286 INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2287 MEDLoaderBase::safeStrCpy(meshName,MED_NAME_SIZE,maa,MEDLoader::_TOO_LONG_STR);
2289 throw INTERP_KERNEL::Exception("writeUMeshesPartitionDirectly : Invalid meshName : Must be different from \"\" !");
2290 std::vector< DataArrayInt * > corr;
2291 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=ParaMEDMEM::MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2292 m->setName(meshName);
2293 std::vector< std::vector<int> > fidsOfGroups;
2294 std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
2295 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=DataArrayInt::MakePartition(corr2,m->getNumberOfCells(),fidsOfGroups);
2296 for(std::vector< DataArrayInt * >::iterator it=corr.begin();it!=corr.end();it++)
2299 std::vector<const MEDCouplingUMesh *> mv(1); mv[0]=m;
2300 std::vector<const DataArrayInt *> famv(1); famv[0]=arr2;
2301 writeUMeshesDirectly(fileName,mv,famv,forceFromScratch,isRenumbering);
2302 // families creation
2303 std::set<int> familyIds;
2304 for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGroups.begin();it1!=fidsOfGroups.end();it1++)
2305 for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
2306 familyIds.insert(*it2);
2307 std::vector< std::vector<int> > gidsOfFamilies(familyIds.size());
2309 for(std::set<int>::const_iterator it=familyIds.begin();it!=familyIds.end();it++,fid++)
2312 for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGroups.begin();it1!=fidsOfGroups.end();it1++,gid++)
2313 for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
2315 gidsOfFamilies[fid].push_back(gid);
2318 med_idt fid2=MEDfileOpen(fileName,MED_ACC_RDWR);
2319 for(std::set<int>::const_iterator it=familyIds.begin();it!=familyIds.end();it++,fid++)
2321 int ngro=gidsOfFamilies[fid].size();
2322 INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
2323 for(int i=0;i<ngro;i++)
2324 MEDLoaderBase::safeStrCpy2(meshes[gidsOfFamilies[fid][i]]->getName(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_LNAME_SIZE-1 to avoid to write '\0' on next compo
2325 std::ostringstream oss; oss << "Family_" << *it;
2326 INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2327 MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,famName,MEDLoader::_TOO_LONG_STR);
2328 MEDfamilyCr(fid2,maa,famName,*it,ngro,groName);
2334 * This method makes the assumption that f->getMesh() nodes are fully included in already written mesh in 'fileName'.
2335 * @param thisMeshNodeIds points to a tab of size f->getMesh()->getNumberOfNodes() that says for a node i in f->getMesh() that its id is thisMeshNodeIds[i] is already written mesh.
2337 void MEDLoaderNS::appendNodeProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshNodeIds)
2341 INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2342 MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
2343 med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
2344 int nbOfNodes=f->getMesh()->getNumberOfNodes();
2345 const double *pt=f->getArray()->getConstPointer();
2346 INTERP_KERNEL::AutoPtr<int> profile=new int[nbOfNodes];
2347 std::ostringstream oss; oss << "Pfln" << f->getName();
2348 INTERP_KERNEL::AutoPtr<char> profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2349 MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR);
2350 std::transform(thisMeshNodeIds,thisMeshNodeIds+nbOfNodes,(int *)profile,std::bind2nd(std::plus<int>(),1));
2351 MEDprofileWr(fid,profileName,nbOfNodes,profile);
2352 MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE,MED_NONE,MED_COMPACT_PFLMODE,profileName,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfNodes,(const unsigned char*)pt);
2357 * This method makes the assumption that f->getMesh() cells are fully included in already written mesh in 'fileName'.
2358 * @param thisMeshCellIdsPerType points to a tab of size f->getMesh()->getNumberOfCells() that says for a cell i in f->getMesh() that its id is thisMeshCellIds[i] of corresponding type is already written mesh.
2360 void MEDLoaderNS::appendCellProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIdsPerType)
2364 int nbComp=f->getNumberOfComponents();
2365 med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
2366 std::list<MEDLoader::MEDFieldDoublePerCellType> split;
2367 prepareCellFieldDoubleForWriting(f,thisMeshCellIdsPerType,split);
2368 const double *pt=f->getArray()->getConstPointer();
2370 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
2372 INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2373 MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
2374 INTERP_KERNEL::AutoPtr<char> profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2375 std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++;
2376 MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR);
2377 const std::vector<int>& ids=(*iter).getCellIdPerType();
2378 int *profile=new int [ids.size()];
2379 std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus<int>(),1));
2380 MEDprofileWr(fid,profileName,ids.size(),profile);
2382 MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,profileName,
2383 MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt);
2384 pt+=(*iter).getNbOfTuple()*nbComp;
2389 void MEDLoaderNS::appendNodeElementProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIdsPerType)
2393 int nbComp=f->getNumberOfComponents();
2394 med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
2395 std::list<MEDLoader::MEDFieldDoublePerCellType> split;
2396 prepareCellFieldDoubleForWriting(f,thisMeshCellIdsPerType,split);
2397 const double *pt=f->getArray()->getConstPointer();
2399 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
2401 INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2402 MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
2403 INTERP_KERNEL::AutoPtr<char> profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2404 std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++;
2405 MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR);
2406 const std::vector<int>& ids=(*iter).getCellIdPerType();
2407 int *profile=new int [ids.size()];
2408 std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus<int>(),1));
2409 MEDprofileWr(fid,profileName,ids.size(),profile);
2411 int nbPtPerCell=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getNumberOfNodes();
2412 int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType());
2413 int nbOfValues=nbPtPerCell*nbOfEntity;
2414 MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE_ELEMENT,typmai3[(int)(*iter).getType()],
2415 MED_COMPACT_PFLMODE,profileName,
2416 MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,
2417 nbOfEntity,(const unsigned char*)pt);
2418 pt+=nbOfValues*nbComp;
2424 * This method performs the classical job for fields before any values setting.
2426 med_idt MEDLoaderNS::appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, med_int& numdt, med_int& numo, med_float& dt)
2428 std::string fieldName(f->getName());
2429 if(fieldName.empty())
2430 throw INTERP_KERNEL::Exception("MEDLoaderNS::appendFieldSimpleAtt : Trying to store a field with no name ! MED file format requires a NON EMPTY field name !");
2431 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDWR);
2432 int nbComp=f->getNumberOfComponents();
2433 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
2434 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
2435 for(int i=0;i<nbComp;i++)
2437 std::string info=f->getArray()->getInfoOnComponent(i);
2439 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
2440 MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);
2441 MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);
2443 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
2444 INTERP_KERNEL::AutoPtr<char> maaname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2445 INTERP_KERNEL::AutoPtr<char> fname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2446 MEDLoaderBase::safeStrCpy(f->getName(),MED_NAME_SIZE,fname,MEDLoader::_TOO_LONG_STR);
2447 MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,maaname,MEDLoader::_TOO_LONG_STR);
2448 MEDLoaderBase::safeStrCpy(f->getTimeUnit(),MED_SNAME_SIZE,dt_unit,MEDLoader::_TOO_LONG_STR);
2449 MEDfieldCr(fid,fname,MED_FLOAT64,nbComp,comp,unit,dt_unit,maaname);
2450 ParaMEDMEM::TypeOfTimeDiscretization td=f->getTimeDiscretization();
2451 if(td==ParaMEDMEM::NO_TIME)
2453 numdt=MED_NO_DT; numo=MED_NO_IT; dt=0.0;
2455 else if(td==ParaMEDMEM::ONE_TIME)
2458 double tmp0=f->getTime(tmp1,tmp2);
2459 numdt=(med_int)tmp1; numo=(med_int)tmp2;
2465 void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f2)
2470 const ParaMEDMEM::MEDCouplingFieldDouble *f=f2;
2471 const MEDCouplingMesh *mesh=f->getMesh();
2472 const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2474 throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !");
2475 bool renum=!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
2478 ParaMEDMEM::MEDCouplingFieldDouble *f3=f2->clone(true);
2479 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=meshC->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
2480 f3->renumberCells(da->getConstPointer(),false);
2484 int nbComp=f->getNumberOfComponents();
2485 med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
2486 const double *pt=f->getArray()->getConstPointer();
2487 INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2488 MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
2489 switch(f->getTypeOfField())
2491 case ParaMEDMEM::ON_CELLS:
2493 std::list<MEDLoader::MEDFieldDoublePerCellType> split;
2494 prepareCellFieldDoubleForWriting(f,0,split);
2495 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
2497 MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,
2498 MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt);
2499 pt+=(*iter).getNbOfTuple()*nbComp;
2503 case ParaMEDMEM::ON_NODES:
2505 int nbOfTuples=f->getArray()->getNumberOfTuples();
2506 MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE,MED_NONE,MED_COMPACT_PFLMODE,
2507 MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfTuples,(const unsigned char*)pt);
2510 case ParaMEDMEM::ON_GAUSS_PT:
2512 std::list<MEDLoader::MEDFieldDoublePerCellType> split;
2513 prepareCellFieldDoubleForWriting(f,0,split);
2515 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
2517 INTERP_KERNEL::AutoPtr<char> nomGauss=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2518 std::ostringstream oss; oss << "GP_" << f->getName() << idGp++;
2519 MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,nomGauss,MEDLoader::_TOO_LONG_STR);
2520 int id=f->getGaussLocalizationIdOfOneType((*iter).getType());
2521 const MEDCouplingGaussLocalization& gl=f->getGaussLocalization(id);
2522 MEDlocalizationWr(fid,nomGauss,typmai3[(int)(*iter).getType()],mesh->getMeshDimension(),&gl.getRefCoords()[0],MED_FULL_INTERLACE,
2523 gl.getNumberOfGaussPt(),&gl.getGaussCoords()[0],&gl.getWeights()[0],MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT);
2524 int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType());
2525 int nbOfValues=gl.getNumberOfGaussPt()*nbOfEntity;
2526 INTERP_KERNEL::AutoPtr<char> fieldname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2527 MEDLoaderBase::safeStrCpy(f->getName(),MED_NAME_SIZE,fieldname,MEDLoader::_TOO_LONG_STR);
2528 MEDfieldValueWithProfileWr(fid,fieldname,numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,
2529 MED_ALLENTITIES_PROFILE,nomGauss,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt);
2530 pt+=nbOfValues*nbComp;
2534 case ParaMEDMEM::ON_GAUSS_NE:
2536 std::list<MEDLoader::MEDFieldDoublePerCellType> split;
2537 prepareCellFieldDoubleForWriting(f,0,split);
2538 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
2540 int nbPtPerCell=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getNumberOfNodes();
2541 int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType());
2542 int nbOfValues=nbPtPerCell*nbOfEntity;
2543 MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE_ELEMENT,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,
2544 MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt);
2545 pt+=nbOfValues*nbComp;
2550 throw INTERP_KERNEL::Exception("Not managed this type of FIELD !");
2558 * This method splits field 'f' into types to be ready for writing.
2559 * @param cellIdsPerType this parameter can be 0 if not in profile mode. If it is != 0 this array is of size f->getMesh()->getNumberOfCells().
2561 void MEDLoaderNS::prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *cellIdsPerType, std::list<MEDLoader::MEDFieldDoublePerCellType>& split)
2563 int nbComp=f->getNumberOfComponents();
2564 const MEDCouplingMesh *mesh=f->getMesh();
2565 const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2567 throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !");
2568 if(!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
2569 throw INTERP_KERNEL::Exception("Unstructuded mesh has not consecutive cell types !");
2570 const int *connI=meshC->getNodalConnectivityIndex()->getConstPointer();
2571 const int *conn=meshC->getNodalConnectivity()->getConstPointer();
2572 int nbOfCells=meshC->getNumberOfCells();
2573 INTERP_KERNEL::NormalizedCellType curType;
2574 const int *wCellIdsPT=cellIdsPerType;
2575 for(const int *pt=connI;pt!=connI+nbOfCells;)
2577 curType=(INTERP_KERNEL::NormalizedCellType)conn[*pt];
2578 const int *pt2=std::find_if(pt+1,connI+nbOfCells,ConnReaderML(conn,(int)curType));
2580 split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,0,0));
2583 split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,wCellIdsPT,0));
2584 wCellIdsPT+=std::distance(pt,pt2);
2590 void MEDLoaderNS::writeFieldAndMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch)
2592 f->checkCoherency();
2593 std::string meshName(f->getMesh()->getName());
2594 if(meshName.empty())
2595 throw INTERP_KERNEL::Exception("Trying to write a mesh (f->getMesh()) with no name ! MED file format needs a not empty mesh name !");
2596 std::string fieldName(f->getName());
2597 if(fieldName.empty())
2598 throw INTERP_KERNEL::Exception("Trying to write a field with no name ! MED file format needs a not empty field name !");
2599 MEDCouplingUMesh *mesh=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh()));
2603 std::vector<const MEDCouplingUMesh *> meshV(1); meshV[0]=mesh;
2604 std::vector<const DataArrayInt *> famV(1); famV[0]=0;
2605 writeUMeshesDirectly(fileName,meshV,famV,forceFromScratch,isRenumbering);
2608 MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> f2=f->clone(true);
2609 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=mesh->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
2610 f2->renumberCells(da->getConstPointer(),false);
2611 appendFieldDirectly(fileName,f2);
2614 appendFieldDirectly(fileName,f);
2617 throw INTERP_KERNEL::Exception("The mesh underlying field is not unstructured ! Only unstructured mesh supported for writting now !");
2621 * When called this method expectes that file 'fileName' is already existing and has a mesh with name equal to
2622 * f->getMesh()->getName(). If not the behaviour of this method is not warranted.
2623 * This method reads the corresponding mesh into the file and try to fit it with f->getMesh().
2624 * If it appears that f->getMesh() equals exactly mesh into the file
2626 void MEDLoaderNS::writeFieldTryingToFitExistingMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f)
2628 std::vector<int> poss;
2629 int mDimInFile=MEDLoaderNS::readUMeshDimFromFile(fileName,f->getMesh()->getName(),poss);
2630 int mdim=f->getMesh()->getMeshDimension();
2631 int f2=mdim-mDimInFile;
2632 if(std::find(poss.begin(),poss.end(),f2)==poss.end())
2634 std::ostringstream oss; oss << "Trying to fit with the existing \"" << f->getMesh()->getName() << "mesh in file \"" << fileName;
2635 oss << "\" but meshdimension does not match !";
2636 throw INTERP_KERNEL::Exception(oss.str().c_str());
2638 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=MEDLoader::ReadUMeshFromFile(fileName,f->getMesh()->getName(),f2);
2639 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m2=MEDCouplingUMesh::MergeUMeshes(m,(MEDCouplingUMesh *)f->getMesh());
2640 bool areNodesMerged;
2642 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=m2->mergeNodes(MEDLoader::_EPS_FOR_NODE_COMP,areNodesMerged,newNbOfNodes);
2643 if(!areNodesMerged || newNbOfNodes!=m->getNumberOfNodes())
2645 std::ostringstream oss; oss << "Nodes in already written mesh \"" << f->getMesh()->getName() << "\" in file \"" << fileName << "\" does not fit coordinates of unstructured grid f->getMesh() !";
2646 throw INTERP_KERNEL::Exception(oss.str().c_str());
2648 switch(f->getTypeOfField())
2650 case ParaMEDMEM::ON_CELLS:
2652 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=m2->zipConnectivityTraducer(MEDLoader::_COMP_FOR_CELL);
2653 if(m2->getNumberOfCells()!=m->getNumberOfCells())
2655 std::ostringstream oss1; oss1 << "Cells in already written mesh \"" << f->getMesh()->getName() << "\" in file \"" << fileName << "\" does not fit connectivity of unstructured grid f->getMesh() !";
2656 throw INTERP_KERNEL::Exception(oss1.str().c_str());
2658 da=m2->convertCellArrayPerGeoType(da2);
2659 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->substr(m2->getNumberOfCells());
2660 da2=m2->convertCellArrayPerGeoType(da3);
2661 appendCellProfileField(fileName,f,da2->getConstPointer());
2664 case ParaMEDMEM::ON_GAUSS_NE:
2666 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=m2->zipConnectivityTraducer(MEDLoader::_COMP_FOR_CELL);
2667 if(m2->getNumberOfCells()!=m->getNumberOfCells())
2669 std::ostringstream oss1; oss1 << "Cells in already written mesh \"" << f->getMesh()->getName() << "\" in file \"" << fileName << "\" does not fit connectivity of unstructured grid f->getMesh() !";
2670 throw INTERP_KERNEL::Exception(oss1.str().c_str());
2672 da=m2->convertCellArrayPerGeoType(da2);
2673 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->substr(m2->getNumberOfCells());
2674 da2=m2->convertCellArrayPerGeoType(da3);
2675 appendNodeElementProfileField(fileName,f,da2->getConstPointer());
2678 case ParaMEDMEM::ON_NODES:
2680 appendNodeProfileField(fileName,f,da->getConstPointer()+m->getNumberOfNodes());
2685 throw INTERP_KERNEL::Exception("Not implemented other profile fitting from already written mesh for fields than on NODES and on CELLS.");
2690 void MEDLoader::WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2692 std::string meshName(mesh->getName());
2693 if(meshName.empty())
2694 throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name !");
2695 int status=MEDLoaderBase::getStatusOfFile(fileName);
2697 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2699 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2700 throw INTERP_KERNEL::Exception(oss.str().c_str());
2702 std::vector<const ParaMEDMEM::MEDCouplingUMesh *> meshV(1); meshV[0]=mesh;
2703 std::vector<const ParaMEDMEM::DataArrayInt *> famV(1); famV[0]=0;
2704 if(writeFromScratch)
2706 MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering);
2709 if(status==MEDLoaderBase::NOT_EXIST)
2711 MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering);
2716 std::vector<std::string> meshNames=GetMeshNames(fileName);
2717 if(std::find(meshNames.begin(),meshNames.end(),meshName)==meshNames.end())
2718 MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,false,isRenumbering);
2721 std::ostringstream oss; oss << "File \'" << fileName << "\' already exists and has already a mesh called \"";
2722 oss << meshName << "\" !";
2723 throw INTERP_KERNEL::Exception(oss.str().c_str());
2728 void MEDLoader::WriteUMeshDep(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2730 std::string meshName(mesh->getName());
2731 if(meshName.empty())
2732 throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name !");
2733 int status=MEDLoaderBase::getStatusOfFile(fileName);
2735 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2737 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2738 throw INTERP_KERNEL::Exception(oss.str().c_str());
2740 std::vector<const ParaMEDMEM::MEDCouplingUMesh *> meshV(1); meshV[0]=mesh;
2741 std::vector<const ParaMEDMEM::DataArrayInt *> famV(1); famV[0]=0;
2742 if(writeFromScratch)
2744 MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering);
2747 if(status==MEDLoaderBase::NOT_EXIST)
2749 MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering);
2753 MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,false,isRenumbering);
2756 void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2758 std::string meshName(meshNameC);
2759 if(meshName.empty())
2760 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 !");
2761 int status=MEDLoaderBase::getStatusOfFile(fileName);
2762 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2764 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2765 throw INTERP_KERNEL::Exception(oss.str().c_str());
2768 throw INTERP_KERNEL::Exception("List of meshes must be not empty !");
2769 const DataArrayDouble *coords=meshes.front()->getCoords();
2770 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
2771 if(coords!=(*iter)->getCoords())
2772 throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !");
2773 std::set<std::string> tmp;
2774 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
2776 if(tmp.find((*iter)->getName())==tmp.end())
2777 tmp.insert((*iter)->getName());
2779 throw INTERP_KERNEL::Exception("The names of meshes must be different each other !");
2782 if(writeFromScratch)
2784 MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true);
2787 if(status==MEDLoaderBase::NOT_EXIST)
2789 MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true);
2794 std::vector<std::string> meshNames=GetMeshNames(fileName);
2795 if(std::find(meshNames.begin(),meshNames.end(),meshName)==meshNames.end())
2796 MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,false);
2799 std::ostringstream oss; oss << "File \'" << fileName << "\' already exists and has already a mesh called \"";
2800 oss << meshName << "\" !";
2801 throw INTERP_KERNEL::Exception(oss.str().c_str());
2806 void MEDLoader::WriteUMeshesPartitionDep(const char *fileName, const char *meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2808 std::string meshName(meshNameC);
2809 if(meshName.empty())
2810 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 !");
2811 int status=MEDLoaderBase::getStatusOfFile(fileName);
2812 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2814 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2815 throw INTERP_KERNEL::Exception(oss.str().c_str());
2818 throw INTERP_KERNEL::Exception("List of meshes must be not empty !");
2819 const DataArrayDouble *coords=meshes.front()->getCoords();
2820 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
2821 if(coords!=(*iter)->getCoords())
2822 throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !");
2823 std::set<std::string> tmp;
2824 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
2826 if(tmp.find((*iter)->getName())==tmp.end())
2827 tmp.insert((*iter)->getName());
2829 throw INTERP_KERNEL::Exception("The names of meshes must be different each other !");
2832 if(writeFromScratch)
2834 MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true);
2837 if(status==MEDLoaderBase::NOT_EXIST)
2839 MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true);
2844 MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,false);
2848 void MEDLoader::WriteUMeshes(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2850 int status=MEDLoaderBase::getStatusOfFile(fileName);
2851 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2853 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2854 throw INTERP_KERNEL::Exception(oss.str().c_str());
2857 throw INTERP_KERNEL::Exception("List of meshes must be not empty !");
2858 std::string meshName(meshes[0]->getName());
2859 if(meshName.empty())
2860 throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name : change name of first element of 2nd parameter !");
2861 const DataArrayDouble *coords=meshes.front()->getCoords();
2862 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
2863 if(coords!=(*iter)->getCoords())
2864 throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !");
2866 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
2868 if(tmp.find((*iter)->getMeshDimension())==tmp.end())
2869 tmp.insert((*iter)->getMeshDimension());
2871 throw INTERP_KERNEL::Exception("The mesh dimension of meshes must be different each other !");
2875 std::vector<const DataArrayInt *> families(meshes.size());
2876 if(writeFromScratch)
2878 MEDLoaderNS::writeUMeshesDirectly(fileName,meshes,families,true,isRenumbering);
2881 if(status==MEDLoaderBase::NOT_EXIST)
2883 MEDLoaderNS::writeUMeshesDirectly(fileName,meshes,families,true,isRenumbering);
2888 MEDLoaderNS::writeUMeshesDirectly(fileName,meshes,families,false,isRenumbering);
2893 void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2895 int status=MEDLoaderBase::getStatusOfFile(fileName);
2896 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2898 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2899 throw INTERP_KERNEL::Exception(oss.str().c_str());
2901 if(writeFromScratch)
2903 MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
2906 if(status==MEDLoaderBase::NOT_EXIST)
2908 MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
2913 std::vector<std::string> meshNames=GetMeshNames(fileName);
2914 std::string fileNameCpp(f->getMesh()->getName());
2915 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
2916 MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,false);
2918 MEDLoaderNS::writeFieldTryingToFitExistingMesh(fileName,f);
2922 void MEDLoader::WriteFieldDep(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2924 int status=MEDLoaderBase::getStatusOfFile(fileName);
2925 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2927 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2928 throw INTERP_KERNEL::Exception(oss.str().c_str());
2930 if(writeFromScratch)
2932 MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
2935 if(status==MEDLoaderBase::NOT_EXIST)
2937 MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
2941 MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,false);
2944 void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception)
2946 f->checkCoherency();
2947 int status=MEDLoaderBase::getStatusOfFile(fileName);
2948 if(status!=MEDLoaderBase::EXIST_RW)
2950 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
2951 throw INTERP_KERNEL::Exception(oss.str().c_str());
2953 MEDLoaderNS::appendFieldDirectly(fileName,f);