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
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDLoader.hxx"
22 #include "MEDLoaderBase.hxx"
23 #include "MEDFileUtilities.hxx"
24 #include "CellModel.hxx"
25 #include "MEDCouplingUMesh.hxx"
26 #include "MEDCouplingMemArray.hxx"
27 #include "MEDCouplingFieldDouble.hxx"
28 #include "MEDCouplingGaussLocalization.hxx"
29 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
31 #include "InterpKernelAutoPtr.hxx"
44 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
67 med_geometry_type typmainoeud[1] = { MED_NONE };
69 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
70 INTERP_KERNEL::NORM_SEG2,
71 INTERP_KERNEL::NORM_SEG3,
72 INTERP_KERNEL::NORM_SEG4,
73 INTERP_KERNEL::NORM_TRI3,
74 INTERP_KERNEL::NORM_QUAD4,
75 INTERP_KERNEL::NORM_TRI6,
76 INTERP_KERNEL::NORM_TRI7,
77 INTERP_KERNEL::NORM_QUAD8,
78 INTERP_KERNEL::NORM_QUAD9,
79 INTERP_KERNEL::NORM_TETRA4,
80 INTERP_KERNEL::NORM_PYRA5,
81 INTERP_KERNEL::NORM_PENTA6,
82 INTERP_KERNEL::NORM_HEXA8,
83 INTERP_KERNEL::NORM_HEXGP12,
84 INTERP_KERNEL::NORM_TETRA10,
85 INTERP_KERNEL::NORM_PYRA13,
86 INTERP_KERNEL::NORM_PENTA15,
87 INTERP_KERNEL::NORM_HEXA20,
88 INTERP_KERNEL::NORM_HEXA27,
89 INTERP_KERNEL::NORM_POLYGON,
90 INTERP_KERNEL::NORM_POLYHED };
92 med_geometry_type typmai3[34] = { MED_POINT1,//0
128 double MEDLoader::_EPS_FOR_NODE_COMP=1.e-12;
130 int MEDLoader::_COMP_FOR_CELL=0;
132 int MEDLoader::_TOO_LONG_STR=0;
134 using namespace ParaMEDMEM;
138 namespace MEDLoaderNS
140 class FieldPerTypeCopier
143 FieldPerTypeCopier(double *ptr):_ptr(ptr) { }
144 void operator()(const MEDLoader::MEDFieldDoublePerCellType& elt) { _ptr=std::copy(elt.getArray(),elt.getArray()+elt.getNbOfValues(),_ptr); }
152 ConnReaderML(const int *c, int val):_conn(c),_val(val) { }
153 bool operator() (const int& pos) { return _conn[pos]!=_val; }
159 std::vector<std::string> getMeshNamesFid(med_idt fid);
160 void readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName,
161 int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField,
162 std::list<MEDLoader::MEDFieldDoublePerCellType>& field,
163 double& time, std::vector<std::string>& infos);
164 std::vector<int> getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector<std::string>& fams);
165 std::vector<int> getIdsFromGroups(const char *fileName, const char *meshName, const std::vector<std::string>& grps);
166 med_int getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception);
167 void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity);
168 int readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector<int>& possibilities);
169 void readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn, std::string& desc);
170 int buildMEDSubConnectivityOfOneType(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families, INTERP_KERNEL::NormalizedCellType type,
171 std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
172 std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
173 MEDCouplingUMesh *readUMeshFromFileLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<int>& ids,
174 const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception);
175 void tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list<MEDLoader::MEDConnOfOneElemType>& medConnFrmt,
176 const std::vector<int>& familiesToKeep,
178 DataArrayInt* &connIndex,
180 ParaMEDMEM::DataArrayDouble *buildArrayFromRawData(const std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerType,
181 const std::vector<std::string>& infos);
182 int buildMEDSubConnectivityOfOneTypesPolyg(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
183 std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
184 int buildMEDSubConnectivityOfOneTypesPolyh(const std::vector<const DataArrayInt *>&conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
185 std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
186 std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
187 int buildMEDSubConnectivityOfOneTypeStaticTypes(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
188 INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
189 ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order,
190 ParaMEDMEM::TypeOfField typeOfOutField) throw(INTERP_KERNEL::Exception);
191 ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev2(const char *fileName, ParaMEDMEM::TypeOfField typeOfOutField, unsigned meshDim, const int *renumCell, const ParaMEDMEM::MEDCouplingUMesh *mesh,
192 const std::vector<std::string>& infos, const char *fieldName, int iteration, int order, double time,
193 std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerCellType) throw(INTERP_KERNEL::Exception);
194 med_idt appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, med_int& numdt, med_int& numo, med_float& dt);
195 void appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f);
196 void appendNodeProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshNodeIds);
197 void appendCellProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIds);
198 void appendNodeElementProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIds);
199 void prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *cellIds, std::list<MEDLoader::MEDFieldDoublePerCellType>& split);
200 void fillGaussDataOnField(const char *fileName, const std::list<MEDLoader::MEDFieldDoublePerCellType>& data, MEDCouplingFieldDouble *f);
201 void writeUMeshesDirectly(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& mesh, const std::vector<const DataArrayInt *>& families, bool forceFromScratch, bool &isRenumbering);
202 void writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool forceFromScratch);
203 void writeFieldAndMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch);
204 void writeFieldTryingToFitExistingMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f);
210 * 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.
212 void MEDLoader::setEpsilonForNodeComp(double val) throw(INTERP_KERNEL::Exception)
214 _EPS_FOR_NODE_COMP=val;
218 * 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.
220 void MEDLoader::setCompPolicyForCell(int val) throw(INTERP_KERNEL::Exception)
226 * This method set the behaviour of MEDLoader when a too long string is seen in datastructure before copy it in MED file.
227 * By default (0) an exception is thrown. If equal to 1 a warning is emitted in std_err but no exception is thrown.
229 void MEDLoader::setTooLongStrPolicy(int val) throw(INTERP_KERNEL::Exception)
235 * @param lgth is the size of fam tab. For classical types conn is size of 'lgth'*number_of_nodes_in_type.
236 * @param index is optionnal only for polys. Set it to 0 if it is not the case.
237 * @param connLgth is the size of conn in the case of poly. Unsued if it is not the case.
239 MEDLoader::MEDConnOfOneElemType::MEDConnOfOneElemType(INTERP_KERNEL::NormalizedCellType type, int *conn, int *index, int *fam, int lgth, int connLgth):_lgth(lgth),_fam(fam),
240 _conn(conn),_index(index),
241 _global(0),_conn_lgth(connLgth),
246 void MEDLoader::MEDConnOfOneElemType::setGlobal(int *global)
256 void MEDLoader::MEDConnOfOneElemType::releaseArray()
264 MEDLoader::MEDFieldDoublePerCellType::MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int ntuple,
265 const int *cellIdPerType, const char *locName):_ntuple(ntuple),_ncomp(ncomp),_values(values),_type(type)
268 _cell_id_per_type.insert(_cell_id_per_type.end(),cellIdPerType,cellIdPerType+ntuple);
273 void MEDLoader::MEDFieldDoublePerCellType::releaseArray()
280 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
282 med_mesh_type type_maillage;
283 char maillage_description[MED_COMMENT_SIZE+1];
284 char dtunit[MED_COMMENT_SIZE+1];
287 char nommaa[MED_NAME_SIZE+1];
288 med_axis_type axistype;
289 med_sorting_type stype;
290 med_int n=MEDnMesh(fid);
291 std::vector<std::string> ret(n);
294 int naxis=MEDmeshnAxis(fid,i+1);
295 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
296 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
298 MEDmeshInfo(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit);
299 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
305 void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list<MEDLoader::MEDFieldDoublePerCellType>& data, MEDCouplingFieldDouble *f)
307 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
308 char locName[MED_NAME_SIZE+1];
309 int nloc=MEDnLocalization(fid);
310 med_geometry_type typeGeo;
311 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=data.begin();iter!=data.end();iter++)
313 const std::string& loc=(*iter).getLocName();
317 for(;idLoc<=nloc;idLoc++)
319 char geointerpname[MED_NAME_SIZE+1]="";
320 char ipointstructmeshname[MED_NAME_SIZE+1]="";
321 med_int nsectionmeshcell;
322 med_geometry_type sectiongeotype;
323 MEDlocalizationInfo(fid,idLoc,locName,&typeGeo,&spaceDim,&nbOfGaussPt, geointerpname, ipointstructmeshname, &nsectionmeshcell,
328 int dim=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getDimension();
329 int nbPtPerCell=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getNumberOfNodes();
330 std::vector<double> refcoo(nbPtPerCell*dim),gscoo(nbOfGaussPt*dim),w(nbOfGaussPt);
331 MEDlocalizationRd(fid,(*iter).getLocName().c_str(),MED_FULL_INTERLACE,&refcoo[0],&gscoo[0],&w[0]);
332 f->setGaussLocalizationOnType((*iter).getType(),refcoo,gscoo,w);
339 void MEDLoader::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception)
341 MEDFileUtilities::CheckFileForRead(fileName);
344 std::vector<std::string> MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception)
346 CheckFileForRead(fileName);
347 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
348 std::vector<std::string> ret=MEDLoaderNS::getMeshNamesFid(fid);
353 std::vector< std::pair<std::string,std::string> > MEDLoader::GetComponentsNamesOfField(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
355 CheckFileForRead(fileName);
356 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
357 med_int nbFields=MEDnField(fid);
358 std::vector<std::string> fields(nbFields);
359 med_field_type typcha;
360 for(int i=0;i<nbFields;i++)
362 med_int ncomp=MEDfieldnComponent(fid,i+1);
363 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
364 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
365 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
368 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
369 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
370 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
371 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
372 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
373 if(curFieldName==fieldName)
375 std::vector< std::pair<std::string,std::string> > ret(ncomp);
376 for(int j=0;j<ncomp;j++)
377 ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
378 MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
381 fields[i]=curFieldName;
383 std::ostringstream oss; oss << "MEDLoader::GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
384 oss << "Possible field names are : " << std::endl;
385 std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
386 throw INTERP_KERNEL::Exception(oss.str().c_str());
390 * Given a 'fileName' and a 'meshName' this method returns global information concerning this mesh.
391 * It returns, in this order :
392 * - 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...
393 * - the mesh dimension
394 * - the space dimension
395 * - the number of nodes
397 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)
399 CheckFileForRead(fileName);
400 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
402 char nommaa[MED_NAME_SIZE+1];
403 char maillage_description[MED_COMMENT_SIZE+1];
404 med_mesh_type type_maillage;
405 std::string trueMeshName;
406 med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
407 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
408 med_sorting_type sortingType;
410 med_axis_type axisType;
411 int naxis=MEDmeshnAxis(fid,meshId);
412 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
413 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
414 MEDmeshInfo(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit);
415 if(type_maillage!=MED_UNSTRUCTURED_MESH)
417 std::ostringstream oss; oss << "MEDLoader::GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
418 oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
419 throw INTERP_KERNEL::Exception(oss.str().c_str());
423 throw INTERP_KERNEL::Exception("MEDLoader::GetUMeshGlobalInfo : multisteps on mesh not managed !");
426 MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
428 std::vector<int> dims;
429 std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
430 med_bool changement,transformation;
431 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
433 med_geometry_type curMedType=typmai[i];
434 int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
437 INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
438 int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
439 dims.push_back(mdimCell);
440 geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
443 int maxLev=*std::max_element(dims.begin(),dims.end());
444 int lowLev=*std::min_element(dims.begin(),dims.end());
445 int nbOfLevels=maxLev-lowLev+1;
446 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
447 for(std::size_t i=0;i<dims.size();i++)
449 ret[maxLev-dims[i]].push_back(geoTypes[i]);
451 numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
455 std::vector<std::string> MEDLoader::GetMeshNamesOnField(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
457 CheckFileForRead(fileName);
458 std::vector<std::string> ret;
460 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
461 med_int nbFields=MEDnField(fid);
463 med_field_type typcha;
464 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
465 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
468 for(int i=0;i<nbFields;i++)
470 med_int ncomp=MEDfieldnComponent(fid,i+1);
471 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
472 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
474 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
475 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
476 std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
477 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
478 if(curFieldName==fieldName)
479 ret.push_back(meshName);
485 std::vector<std::string> MEDLoader::GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
487 CheckFileForRead(fileName);
488 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
489 med_int nfam=MEDnFamily(fid,meshName);
490 std::vector<std::string> ret(nfam);
491 char nomfam[MED_NAME_SIZE+1];
493 for(int i=0;i<nfam;i++)
495 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
496 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
497 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
498 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
499 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
500 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
501 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
502 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
510 std::vector<std::string> MEDLoader::GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception)
512 CheckFileForRead(fileName);
513 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
514 med_int nfam=MEDnFamily(fid,meshName);
515 std::vector<std::string> ret;
516 char nomfam[MED_NAME_SIZE+1];
518 for(int i=0;i<nfam;i++)
520 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
521 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
522 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
523 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
524 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
525 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
526 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
527 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
528 for(int j=0;j<ngro;j++)
530 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
539 std::vector<std::string> MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception)
541 CheckFileForRead(fileName);
542 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
543 med_int nfam=MEDnFamily(fid,meshName);
544 std::vector<std::string> ret;
545 char nomfam[MED_NAME_SIZE+1];
548 for(int i=0;i<nfam && !found;i++)
550 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
551 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
552 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
553 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
554 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
555 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
556 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
557 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
558 found=(cur==famName);
560 for(int j=0;j<ngro;j++)
562 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
569 std::ostringstream oss;
570 oss << "MEDLoader::GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
571 throw INTERP_KERNEL::Exception(oss.str().c_str());
577 std::vector<std::string> MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
579 CheckFileForRead(fileName);
580 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
581 med_int nfam=MEDnFamily(fid,meshName);
582 std::vector<std::string> ret;
583 char nomfam[MED_NAME_SIZE+1];
585 for(int i=0;i<nfam;i++)
587 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
588 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
589 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
590 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
591 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
592 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
593 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
594 for(int j=0;j<ngro;j++)
596 std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
597 if(std::find(ret.begin(),ret.end(),cur)==ret.end())
604 std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
606 CheckFileForRead(fileName);
607 std::vector<ParaMEDMEM::TypeOfField> ret;
608 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
609 med_int nbFields=MEDnField(fid);
611 med_field_type typcha;
612 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
613 med_int numdt=0,numo=0;
615 char pflname[MED_NAME_SIZE+1]="";
616 char locname[MED_NAME_SIZE+1]="";
617 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
618 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
621 for(int i=0;i<nbFields;i++)
623 med_int ncomp=MEDfieldnComponent(fid,i+1);
624 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
625 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
626 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
628 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
629 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
630 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
631 if(curMeshName==meshName)
633 if(curFieldName==fieldName)
639 for(int ii=0;ii<nbPdt && !found;ii++)
641 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
642 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
643 pflname,&profilesize,locname,&nbi);
646 ret.push_back(ON_NODES);
652 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
656 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
657 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
658 pflname,&profilesize,locname,&nbi);
662 ret.push_back(ON_CELLS);
675 std::vector<std::string> MEDLoader::GetAllFieldNames(const char *fileName) throw(INTERP_KERNEL::Exception)
677 CheckFileForRead(fileName);
678 std::vector<std::string> ret;
679 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
680 med_int nbFields=MEDnField(fid);
681 med_field_type typcha;
682 for(int i=0;i<nbFields;i++)
684 med_int ncomp=MEDfieldnComponent(fid,i+1);
685 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
686 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
687 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
688 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
689 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
692 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
693 ret.push_back(std::string(nomcha));
699 std::vector<std::string> MEDLoader::GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
701 CheckFileForRead(fileName);
702 std::vector<std::string> ret;
703 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
704 med_int nbFields=MEDnField(fid);
706 med_field_type typcha;
707 char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
708 char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
710 for(int i=0;i<nbFields;i++)
712 med_int ncomp=MEDfieldnComponent(fid,i+1);
713 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
714 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
715 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
718 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
719 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
720 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
722 if(curMeshName==meshName)
723 ret.push_back(curFieldName);
731 std::vector<std::string> MEDLoader::GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
733 CheckFileForRead(fileName);
737 return GetCellFieldNamesOnMesh(fileName,meshName);
739 return GetNodeFieldNamesOnMesh(fileName,meshName);
741 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
745 std::vector<std::string> MEDLoader::GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
747 CheckFileForRead(fileName);
748 std::vector<std::string> ret;
749 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
750 med_int nbFields=MEDnField(fid);
752 med_field_type typcha;
753 //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
754 med_int numdt=0,numo=0;
756 char pflname[MED_NAME_SIZE+1]="";
757 char locname[MED_NAME_SIZE+1]="";
758 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
759 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
760 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
764 for(int i=0;i<nbFields;i++)
766 med_int ncomp=MEDfieldnComponent(fid,i+1);
767 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
768 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
769 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
770 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
771 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
773 if(curMeshName==meshName)
776 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
780 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
781 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
782 pflname,&profilesize,locname,&nbi);
786 ret.push_back(curFieldName);
796 std::vector<std::string> MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
798 CheckFileForRead(fileName);
799 std::vector<std::string> ret;
800 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
801 med_int nbFields=MEDnField(fid);
802 char pflname[MED_NAME_SIZE+1]="";
803 char locname[MED_NAME_SIZE+1]="";
805 med_field_type typcha;
806 med_int numdt=0,numo=0;
808 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
809 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
810 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
813 for(int i=0;i<nbFields;i++)
815 med_int ncomp=MEDfieldnComponent(fid,i+1);
816 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
817 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
819 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
820 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
821 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
825 MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
826 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
827 pflname,&profilesize,locname,&nbi);
828 if(curMeshName==meshName && nbOfVal>0)
830 ret.push_back(curFieldName);
838 std::vector< std::pair< std::pair<int,int>, double> > MEDLoader::GetAllFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
840 CheckFileForRead(fileName);
841 std::string meshNameCpp(meshName);
842 std::vector< std::pair< std::pair<int,int>, double > > ret;
843 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
844 med_int nbFields=MEDnField(fid);
846 med_field_type typcha;
847 med_int numdt=0,numo=0;
849 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
850 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
851 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
854 for(int i=0;i<nbFields;i++)
856 med_int ncomp=MEDfieldnComponent(fid,i+1);
857 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
858 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
860 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
861 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
862 if(curFieldName==fieldName)
864 for(int k=0;k<nbPdt;k++)
866 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
867 ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
875 double MEDLoader::GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
877 CheckFileForRead(fileName);
878 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
879 med_int nbFields=MEDnField(fid);
881 med_field_type typcha;
882 med_int numdt=0,numo=0;
885 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
886 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
887 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
891 double ret=std::numeric_limits<double>::max();
892 for(int i=0;i<nbFields && !found;i++)
894 med_int ncomp=MEDfieldnComponent(fid,i+1);
895 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
896 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
898 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt);
899 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
900 if(curFieldName==fieldName)
903 for(int k=0;k<nbPdt;k++)
905 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
906 if(numdt==iteration && numo==order)
915 if(!found || !found2)
917 std::ostringstream oss;
918 oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
919 throw INTERP_KERNEL::Exception(oss.str().c_str());
924 std::vector< std::pair<int,int> > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
926 CheckFileForRead(fileName);
930 return GetCellFieldIterations(fileName,meshName,fieldName);
932 return GetNodeFieldIterations(fileName,meshName,fieldName);
934 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
938 std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
940 CheckFileForRead(fileName);
941 std::string meshNameCpp(meshName);
942 std::vector< std::pair<int,int> > ret;
943 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
944 med_int nbFields=MEDnField(fid);
946 med_field_type typcha;
947 med_int numdt=0,numo=0;
949 char pflname[MED_NAME_SIZE+1]="";
950 char locname[MED_NAME_SIZE+1]="";
951 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
952 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
953 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
956 for(int i=0;i<nbFields;i++)
958 med_int ncomp=MEDfieldnComponent(fid,i+1);
959 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
960 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
962 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
963 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
964 if(curFieldName==fieldName)
967 for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
969 for(int k=0;k<nbPdt;k++)
972 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
973 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
974 pflname,&profilesize,locname,&nbi);
975 std::string maa_ass_cpp(maa_ass);
976 if(meshNameCpp==maa_ass_cpp && nbOfVal>0)
979 ret.push_back(std::make_pair(numdt,numo));
989 std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
991 CheckFileForRead(fileName);
992 std::string meshNameCpp(meshName);
993 std::vector< std::pair<int,int> > ret;
994 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
995 med_int nbFields=MEDnField(fid);
997 med_field_type typcha;
998 med_int numdt=0,numo=0;
1000 char pflname[MED_NAME_SIZE+1]="";
1001 char locname[MED_NAME_SIZE+1]="";
1002 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1003 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
1004 INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1007 for(int i=0;i<nbFields;i++)
1009 med_int ncomp=MEDfieldnComponent(fid,i+1);
1010 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
1011 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1013 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
1014 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1015 if(curFieldName==fieldName)
1017 for(int k=0;k<nbPdt;k++)
1019 int profilesize,nbi;
1020 MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
1021 med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
1022 pflname,&profilesize,locname,&nbi);
1023 std::string maa_ass_cpp(maa_ass);
1024 if(meshNameCpp==maa_ass_cpp && nbOfVal>0)
1026 ret.push_back(std::make_pair(numdt,numo));
1036 * 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'
1037 * The returned values are strored in 'field' (sorted by type of cell), time corresponding to field, and 'infos' to load properly little strings.
1038 * The principle of this method is to put into 'field' only data that fulfills \b perfectly request.
1040 void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName,
1041 int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField,
1042 std::list<MEDLoader::MEDFieldDoublePerCellType>& field,
1043 double& time, std::vector<std::string>& infos)
1046 MEDFileUtilities::CheckFileForRead(fileName);
1047 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1048 med_int nbFields=MEDnField(fid);
1050 med_field_type typcha;
1051 char nomcha[MED_NAME_SIZE+1]="";
1052 char pflname [MED_NAME_SIZE+1]="";
1053 char locname [MED_NAME_SIZE+1]="";
1054 std::map<ParaMEDMEM::TypeOfField, med_entity_type> tabEnt;
1055 std::map<ParaMEDMEM::TypeOfField, med_geometry_type *> tabType;
1056 std::map<ParaMEDMEM::TypeOfField, int> tabTypeLgth;
1059 tabEnt[ON_CELLS]=MED_CELL;
1060 tabType[ON_CELLS]=typmai;
1061 tabTypeLgth[ON_CELLS]=MED_N_CELL_FIXED_GEO;
1062 tabEnt[ON_NODES]=MED_NODE;
1063 tabType[ON_NODES]=typmainoeud;
1064 tabTypeLgth[ON_NODES]=1;
1065 tabEnt[ON_GAUSS_PT]=MED_CELL;
1066 tabType[ON_GAUSS_PT]=typmai;
1067 tabTypeLgth[ON_GAUSS_PT]=MED_N_CELL_FIXED_GEO;
1068 tabEnt[ON_GAUSS_NE]=MED_NODE_ELEMENT;
1069 tabType[ON_GAUSS_NE]=typmai;
1070 tabTypeLgth[ON_GAUSS_NE]=MED_N_CELL_FIXED_GEO;
1072 for(int i=0;i<nbFields && !found;i++)
1074 med_int ncomp=MEDfieldnComponent(fid,i+1);
1075 INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
1076 INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
1077 INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
1078 INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1080 MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
1081 std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
1082 std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
1083 found=(curFieldName==fieldName) && (curMeshName==meshName);
1086 infos.resize(ncomp);
1087 for(int ii=0;ii<ncomp;ii++)
1088 infos[ii]=MEDLoaderBase::buildUnionUnit(comp+ii*MED_SNAME_SIZE,MED_SNAME_SIZE,unit+ii*MED_SNAME_SIZE,MED_SNAME_SIZE);
1090 med_int numdt=0,numo=0;
1092 for(int k=0;k<nbPdt && !found2;k++)
1094 MEDfieldComputingStepInfo(fid,fieldName,k+1,&numdt,&numo,&dt);
1095 found2=(numdt==iteration && numo==order);
1101 std::ostringstream oss; oss << "FieldDouble in file \""<< fileName<< "\" with name \"" << fieldName << "\" on mesh \"" << meshName;
1102 oss << "\" does not have such time step : iteration=" << iteration << " order=" << order << std::endl;
1103 throw INTERP_KERNEL::Exception(oss.str().c_str());
1105 for(int j=0;j<tabTypeLgth[typeOfOutField];j++)
1109 int profilesize,nbi;
1110 int nval=MEDfieldnValueWithProfile(fid,fieldName,numdt,numo,tabEnt[typeOfOutField],tabType[typeOfOutField][j],1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi);
1113 double *valr=new double[ncomp*nval*nbi];
1114 MEDfieldValueWithProfileRd(fid,fieldName,iteration,order,tabEnt[typeOfOutField],tabType[typeOfOutField][j],MED_COMPACT_PFLMODE,
1115 pflname,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(unsigned char*)valr);
1116 std::string tmp(locname);
1117 if((locname[0]!='\0' && (typeOfOutField!=ON_GAUSS_PT))
1118 || (locname[0]=='\0' && typeOfOutField==ON_GAUSS_PT))
1123 INTERP_KERNEL::AutoPtr<int> pfl=0;
1124 if(pflname[0]!='\0')
1127 MEDprofileRd(fid,pflname,pfl);
1129 field.push_back(MEDLoader::MEDFieldDoublePerCellType(typmai2[j],valr,ncomp,nval*nbi,pfl,locname));
1137 std::ostringstream oss; oss << "MEDLoaderNS::readFieldDoubleDataInMedFile : no such couple meshName=\"" << meshName << "\", fieldName=\"" << fieldName << "\" in file \"" << fileName << "\" !";
1138 throw INTERP_KERNEL::Exception(oss.str().c_str());
1142 std::vector<int> MEDLoaderNS::getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector<std::string>& fams)
1144 std::vector<int> ret;
1145 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1146 med_int nfam=MEDnFamily(fid,meshName);
1147 char nomfam[MED_NAME_SIZE+1];
1149 for(int i=0;i<nfam;i++)
1151 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
1152 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
1153 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
1154 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
1155 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
1156 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
1157 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
1158 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
1159 if(std::find(fams.begin(),fams.end(),cur)!=fams.end())
1160 ret.push_back(numfam);
1166 std::vector<int> MEDLoaderNS::getIdsFromGroups(const char *fileName, const char *meshName, const std::vector<std::string>& grps)
1168 std::vector<int> ret;
1169 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1170 med_int nfam=MEDnFamily(fid,meshName);
1171 char nomfam[MED_NAME_SIZE+1];
1173 for(int i=0;i<nfam;i++)
1175 int ngro=MEDnFamilyGroup(fid,meshName,i+1);
1176 med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
1177 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
1178 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
1179 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
1180 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
1181 MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
1182 std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
1183 for(int j=0;j<ngro;j++)
1185 std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
1186 if(std::find(grps.begin(),grps.end(),cur2)!=grps.end())
1188 ret.push_back(numfam);
1197 med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception)
1201 std::vector<std::string> meshes=getMeshNamesFid(fid);
1203 throw INTERP_KERNEL::Exception("No mesh in file");
1204 trueMeshName=meshes[0];
1207 std::string meshNameStr(meshName);
1208 std::vector<std::string> meshes=getMeshNamesFid(fid);
1210 throw INTERP_KERNEL::Exception("No mesh in file");
1211 std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
1212 if(iter==meshes.end())
1214 std::ostringstream os2;
1215 os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
1216 std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
1217 throw INTERP_KERNEL::Exception(os2.str().c_str());
1219 trueMeshName=meshName;
1220 return iter-meshes.begin()+1;
1224 * This methods allows to merger all entities and to considerate only cell types.
1226 void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
1228 if(nbOfElemCell>=nbOfElemFace)
1230 whichEntity=MED_CELL;
1231 nbOfElem=nbOfElemCell;
1235 whichEntity=MED_CELL;
1236 nbOfElem=nbOfElemFace;
1241 * This method returns a first quick overview of mesh with name 'meshName' into the file 'fileName'.
1242 * @param possibilities the relativeToMeshDim authorized to returned maxdim. This vector is systematically cleared at the begin of this method.
1243 * @return the maximal mesh dimension of specified mesh. If nothing found -1 is returned.
1245 int MEDLoaderNS::readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector<int>& possibilities)
1247 possibilities.clear();
1248 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1251 char nommaa[MED_NAME_SIZE+1];
1252 char maillage_description[MED_COMMENT_SIZE+1];
1253 med_mesh_type type_maillage;
1255 std::string trueMeshName;
1256 med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
1257 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
1258 med_sorting_type sortingType;
1260 med_axis_type axisType;
1261 int naxis=MEDmeshnAxis(fid,meshId);
1262 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
1263 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
1264 MEDmeshInfo(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit);
1268 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
1270 med_int numdt,numit;
1272 MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
1274 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
1276 med_geometry_type curMedType=typmai[i];
1277 med_bool changement,transformation;
1278 int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
1279 int curNbOfElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);//limitation
1281 med_entity_type whichEntity;
1282 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
1285 INTERP_KERNEL::NormalizedCellType type=typmai2[i];
1286 int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
1287 poss.insert(curDim);
1294 for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
1295 possibilities.push_back(*it-ret);
1302 void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn, std::string& description)
1304 char nommaa[MED_NAME_SIZE+1];
1305 char maillage_description[MED_COMMENT_SIZE+1];
1306 med_mesh_type type_maillage;
1309 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
1310 med_sorting_type sortingType;
1312 med_axis_type axisType;
1313 med_int numdt,numit;
1315 med_bool changement,transformation;
1317 Sdim=MEDmeshnAxis(fid,1);
1318 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(Sdim*MED_SNAME_SIZE);
1319 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(Sdim*MED_SNAME_SIZE);
1320 MEDmeshInfo(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,comp,unit);
1321 description=MEDLoaderBase::buildStringFromFortran(maillage_description,sizeof(maillage_description));
1322 MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
1323 int spaceDim=std::max((int)Mdim,(int)Sdim);
1324 int nCoords=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
1328 throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
1330 coords=DataArrayDouble::New();
1331 coords->alloc(nCoords,spaceDim);
1332 double *coordsPtr=coords->getPointer();
1333 MEDmeshNodeCoordinateRd(fid,nommaa,numdt,numit,MED_FULL_INTERLACE,coordsPtr);
1334 for(int i=0;i<spaceDim;i++)
1336 std::string info=MEDLoaderBase::buildUnionUnit(comp+i*MED_SNAME_SIZE,MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
1337 coords->setInfoOnComponent(i,info.c_str());
1339 for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
1341 med_geometry_type curMedType=typmai[i];
1342 med_entity_type whichEntity;
1343 int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
1344 int curNbOfElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);//limitation
1346 MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
1349 int *connTab=new int[(curMedType%100)*curNbOfElem];
1350 int *fam=new int[curNbOfElem];
1351 MEDLoader::MEDConnOfOneElemType elem(typmai2[i],connTab,0,fam,curNbOfElem,-1);
1352 char *noms=new char[MED_SNAME_SIZE*curNbOfElem+1];
1353 med_bool withname=MED_FALSE,withnumber=MED_FALSE,withfam=MED_FALSE;
1354 int *globArr=new int[curNbOfElem];
1355 MEDmeshElementRd(fid,nommaa,numdt,numit,whichEntity,curMedType,MED_NODAL,MED_FULL_INTERLACE,connTab,&withname,noms,&withnumber,globArr,&withfam,fam);
1357 std::fill(fam,fam+curNbOfElem,0);
1359 //trying to read global numbering
1361 elem.setGlobal(globArr);
1364 //limitation manage withfam==false
1365 conn.push_back(elem);
1368 int curNbOfPolyElem;
1369 int curNbOfPolyElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1;
1370 int curNbOfPolyElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1;//limitation
1371 med_entity_type whichPolyEntity;
1372 MEDLoaderNS::dispatchElems(curNbOfPolyElemM,curNbOfPolyElemF,curNbOfPolyElem,whichPolyEntity);
1373 if(curNbOfPolyElem>0)
1375 med_int arraySize=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
1376 int *index=new int[curNbOfPolyElem+1];
1377 int *locConn=new int[arraySize];
1378 int *fam=new int[curNbOfPolyElem];
1379 int *globArr=new int[curNbOfPolyElem];
1380 MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYGON,locConn,index,fam,curNbOfPolyElem,arraySize);
1381 MEDmeshPolygonRd(fid,nommaa,numdt,numit,MED_CELL,MED_NODAL,index,locConn);
1382 if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
1384 if(MEDmeshEntityFamilyNumberRd(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,fam)!=0)
1385 std::fill(fam,fam+curNbOfPolyElem,0);
1388 std::fill(fam,fam+curNbOfPolyElem,0);
1389 if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
1391 if(MEDmeshEntityNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYGON,globArr)==0)
1392 elem.setGlobal(globArr);
1398 conn.push_back(elem);
1400 curNbOfPolyElem=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1;
1401 if(curNbOfPolyElem>0)
1403 med_int indexFaceLgth,connFaceLgth;
1404 indexFaceLgth=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation);
1405 connFaceLgth=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
1406 INTERP_KERNEL::AutoPtr<int> index=new int[curNbOfPolyElem+1];
1407 INTERP_KERNEL::AutoPtr<int> indexFace=new int[indexFaceLgth];
1408 INTERP_KERNEL::AutoPtr<int> locConn=new int[connFaceLgth];
1409 int *fam=new int[curNbOfPolyElem];
1410 int *globArr=new int[curNbOfPolyElem];
1411 MEDmeshPolyhedronRd(fid,nommaa,numdt,numit,MED_CELL,MED_NODAL,index,indexFace,locConn);
1412 if(MEDmeshnEntity(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
1414 if(MEDmeshEntityFamilyNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,fam)!=0)
1415 std::fill(fam,fam+curNbOfPolyElem,0);
1418 std::fill(fam,fam+curNbOfPolyElem,0);
1419 int arraySize=connFaceLgth;
1420 for(int i=0;i<curNbOfPolyElem;i++)
1421 arraySize+=index[i+1]-index[i]-1;
1422 int *finalConn=new int[arraySize];
1423 int *finalIndex=new int[curNbOfPolyElem+1];
1425 int *wFinalConn=finalConn;
1426 for(int i=0;i<curNbOfPolyElem;i++)
1428 finalIndex[i+1]=finalIndex[i]+index[i+1]-index[i]-1+indexFace[index[i+1]-1]-indexFace[index[i]-1];
1429 wFinalConn=std::copy(locConn+indexFace[index[i]-1]-1,locConn+indexFace[index[i]]-1,wFinalConn);
1430 for(int j=index[i];j<index[i+1]-1;j++)
1433 wFinalConn=std::copy(locConn+indexFace[j]-1,locConn+indexFace[j+1]-1,wFinalConn);
1436 MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYHED,finalConn,finalIndex,fam,curNbOfPolyElem,arraySize);
1437 if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
1439 if(MEDmeshEntityNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,globArr)==0)
1440 elem.setGlobal(globArr);
1446 conn.push_back(elem);
1452 namespace MEDLoaderNS
1455 unsigned calculateHighestMeshDim(const std::list<T>& conn)
1458 for(typename std::list<T>::const_iterator iter=conn.begin();iter!=conn.end();iter++)
1460 unsigned curDim=INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getDimension();
1468 void keepSpecifiedMeshDim(typename std::list<T>& conn, unsigned meshDim)
1470 for(typename std::list<T>::iterator iter=conn.begin();iter!=conn.end();)
1472 unsigned curDim=INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getDimension();
1475 (*iter).releaseArray();
1476 iter=conn.erase(iter);
1484 void keepTypes(typename std::list<T>& conn, const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep)
1486 if(!typesToKeep.empty())
1488 for(typename std::list<T>::iterator iter=conn.begin();iter!=conn.end();)
1490 INTERP_KERNEL::NormalizedCellType curType=(*iter).getType();
1491 if(std::find(typesToKeep.begin(),typesToKeep.end(),curType)==typesToKeep.end())
1493 (*iter).releaseArray();
1494 iter=conn.erase(iter);
1503 class FieldPerTypeAccumulator
1506 int operator()(int res, const MEDLoader::MEDFieldDoublePerCellType& elt) { return res+elt.getNbOfTuple(); }
1509 ParaMEDMEM::DataArrayDouble *MEDLoaderNS::buildArrayFromRawData(const std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerType,
1510 const std::vector<std::string>& infos)
1512 ParaMEDMEM::DataArrayDouble *ret=ParaMEDMEM::DataArrayDouble::New();
1513 int totalNbOfTuple=std::accumulate(fieldPerType.begin(),fieldPerType.end(),0,FieldPerTypeAccumulator());
1514 int nbOfComp=(*fieldPerType.begin()).getNbComp();
1515 double *ptr=new double[nbOfComp*totalNbOfTuple];
1516 ret->useArray(ptr,true,ParaMEDMEM::CPP_DEALLOC,totalNbOfTuple,nbOfComp);
1517 std::for_each(fieldPerType.begin(),fieldPerType.end(),FieldPerTypeCopier(ptr));
1518 for(int i=0;i<nbOfComp;i++)
1519 ret->setInfoOnComponent(i,infos[i].c_str());
1523 class PolyCounterForFams
1526 PolyCounterForFams(int id, const int *index):_id(id),_index(index),_count(0),_sigma(0) { }
1527 void operator()(int val) { if(val==_id) _sigma+=_index[_count+1]-_index[_count]; _count++; }
1528 int getSigma() const { return _sigma; }
1537 * This method fills unstructured connectivity using basic MED file format 'medConnFrmt'.
1538 * If in each elements of 'medConnFrmt' a renumbering cell array is found the aggregate array 'cellRenum' is returned.
1540 void MEDLoaderNS::tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list<MEDLoader::MEDConnOfOneElemType>& medConnFrmt,
1541 const std::vector<int>& familiesToKeep,
1542 DataArrayInt* &conn,
1543 DataArrayInt* &connIndex,
1546 bool keepAll=familiesToKeep.empty();
1547 if(medConnFrmt.empty())
1554 std::list<MEDLoader::MEDConnOfOneElemType>::const_iterator iter=medConnFrmt.begin();
1555 int totalNbOfCells=0;
1556 int totalNbOfMedConn=0;
1559 for(;iter!=medConnFrmt.end();iter++)
1561 if((*iter).getGlobal()==0)
1563 const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::GetCellModel((*iter).getType());
1565 totalNbOfCells+=(*iter).getLength();
1567 for(std::vector<int>::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++)
1568 totalNbOfCells+=std::count((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),*iter2);
1569 if(!cellMod.isDynamic())
1571 totalNbOfMedConn+=(*iter).getLength()*cellMod.getNumberOfNodes();
1573 for(std::vector<int>::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++)
1574 totalNbOfMedConn+=std::count((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),*iter2)*cellMod.getNumberOfNodes();
1577 totalNbOfMedConn+=(*iter).getConnLength();
1579 for(std::vector<int>::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++)
1581 PolyCounterForFams res=std::for_each((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),PolyCounterForFams(*iter2,(*iter).getIndex()));
1582 totalNbOfMedConn+=res.getSigma();
1585 connIndex=DataArrayInt::New();
1586 conn=DataArrayInt::New();
1587 connIndex->alloc(totalNbOfCells+1,1);
1588 int *connIdxPtr=connIndex->getPointer();
1590 conn->alloc(totalNbOfMedConn+totalNbOfCells,1);
1591 int *connPtr=conn->getPointer();
1593 cellRenum=new int[totalNbOfCells];
1594 int *renumW=cellRenum;
1595 for(iter=medConnFrmt.begin();iter!=medConnFrmt.end();iter++)
1597 INTERP_KERNEL::NormalizedCellType type=(*iter).getType();
1598 const int *sourceConn=(*iter).getArray();
1599 const int *sourceIndex=(*iter).getIndex();
1600 const int *globalNum=(*iter).getGlobal();
1601 const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::GetCellModel(type);
1602 int nbOfCellsInCurType;
1603 int nbOfNodesIn1Cell=cellMod.getNumberOfNodes();
1604 nbOfCellsInCurType=(*iter).getLength();
1605 bool isDyn=cellMod.isDynamic();
1607 for(int i=0;i<nbOfCellsInCurType;i++)
1610 {//duplication of next 3 lines needed.
1611 *connIdxPtr=connFillId;
1614 *renumW++=globalNum[i];
1616 tmpConnPtr=std::transform(sourceConn,sourceConn+nbOfNodesIn1Cell,connPtr,std::bind2nd(std::minus<int>(),1));
1618 tmpConnPtr=std::transform(sourceConn,sourceConn+sourceIndex[i+1]-sourceIndex[i],connPtr,std::bind2nd(std::minus<int>(),1));
1620 nbOfNodesIn1Cell=tmpConnPtr-connPtr;
1621 connFillId+=nbOfNodesIn1Cell+1;
1624 else if(std::find(familiesToKeep.begin(),familiesToKeep.end(),(*iter).getFam()[i])!=familiesToKeep.end())
1625 {//duplication of next 3 lines needed.
1626 *connIdxPtr=connFillId;
1629 *renumW++=globalNum[i];
1631 tmpConnPtr=std::transform(sourceConn,sourceConn+nbOfNodesIn1Cell,connPtr,std::bind2nd(std::minus<int>(),1));
1632 else//The duplication of code is motivated by the line underneath.
1633 tmpConnPtr=std::transform((*iter).getArray()+sourceIndex[i]-1,(*iter).getArray()+sourceIndex[i+1]-1,connPtr,std::bind2nd(std::minus<int>(),1));
1635 nbOfNodesIn1Cell=tmpConnPtr-connPtr;
1636 connFillId+=nbOfNodesIn1Cell+1;
1639 sourceConn+=nbOfNodesIn1Cell;
1641 *connIdxPtr=connFillId;
1645 namespace MEDLoaderNS
1648 void releaseMEDFileCoreFrmt(typename std::list<T>& medConnFrmt)
1650 for(typename std::list<T>::iterator iter=medConnFrmt.begin();iter!=medConnFrmt.end();iter++)
1651 (*iter).releaseArray();
1652 medConnFrmt.clear();
1657 * This method builds a sub set of connectivity for a given type 'type'. \b WARNING connV,connVIndex and familiesV must have same size !
1658 * @param connV input containing connectivity with MEDCoupling format.
1659 * @param connVIndex input containing connectivity index in MEDCoupling format.
1660 * @param familiesV input that may be equal to 0. This specifies an array specifying cell family foreach cell.
1661 * @param type input specifying which cell types will be extracted in conn4MEDFile.
1662 * @param conn4MEDFile output containing the connectivity directly understandable by MEDFile; conn4MEDFile has to be empty before this method called.
1663 * @param connIndex4MEDFile output containing index connectivity understandable by MEDFile; only used by polygons and polyhedrons (it is face nodal connec).
1664 * @param connIndexRk24MEDFile output containing index of rank 2 understandable by MEDFile; only used by polyhedrons.
1665 * @param fam4MEDFile output containing family number of cells whose type is 'type'. This output is updated only if 'families' is different than 0.
1666 * @return nb of elements extracted.
1668 int MEDLoaderNS::buildMEDSubConnectivityOfOneTypeStaticTypes(const std::vector<const DataArrayInt *>& connV, const std::vector<const DataArrayInt *>& connVIndex, const std::vector<const DataArrayInt *>& familiesV,
1669 INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
1672 int nbOfMeshes=connV.size();
1674 for(int i=0;i<nbOfMeshes;i++)
1676 const DataArrayInt *conn=connV[i];
1677 const DataArrayInt *connIndex=connVIndex[i];
1678 const DataArrayInt *families=familiesV[i];
1679 int nbOfElem=connIndex->getNbOfElems()-1;
1680 const int *connPtr=conn->getConstPointer();
1681 const int *connIdxPtr=connIndex->getConstPointer();
1682 const int *famPtr=0;
1684 famPtr=families->getConstPointer();
1685 for(int ii=0;ii<nbOfElem;ii++)
1687 int delta=connIdxPtr[1]-connIdxPtr[0];
1690 conn4MEDFile.insert(conn4MEDFile.end(),connPtr+1,connPtr+delta);
1692 fam4MEDFile.push_back(famPtr[ii]);
1693 renumber.push_back(ii+1+renumOffset);
1699 renumOffset+=nbOfElem;
1701 std::transform(conn4MEDFile.begin(),conn4MEDFile.end(),conn4MEDFile.begin(),std::bind2nd(std::plus<int>(),1));
1705 int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyg(const std::vector<const DataArrayInt *>&connV, const std::vector<const DataArrayInt *>& connVIndex, const std::vector<const DataArrayInt *>& familiesV,
1706 std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
1709 int nbOfMeshes=connV.size();
1710 connIndex4MEDFile.push_back(1);
1712 for(int i=0;i<nbOfMeshes;i++)
1714 const DataArrayInt *conn=connV[i];
1715 const DataArrayInt *connIndex=connVIndex[i];
1716 const DataArrayInt *families=familiesV[i];
1717 int nbOfElem=connIndex->getNbOfElems()-1;
1718 const int *connPtr=conn->getConstPointer();
1719 const int *connIdxPtr=connIndex->getConstPointer();
1720 const int *famPtr=0;
1722 famPtr=families->getConstPointer();
1723 for(int ii=0;ii<nbOfElem;ii++)
1725 int delta=connIdxPtr[1]-connIdxPtr[0];
1726 if(*connPtr==INTERP_KERNEL::NORM_POLYGON)
1728 conn4MEDFile.insert(conn4MEDFile.end(),connPtr+1,connPtr+delta);
1729 connIndex4MEDFile.push_back(connIndex4MEDFile.back()+delta-1);
1731 fam4MEDFile.push_back(famPtr[ii]);
1732 renumber.push_back(ii+1+renumOffset);
1738 renumOffset+=nbOfElem;
1740 std::transform(conn4MEDFile.begin(),conn4MEDFile.end(),conn4MEDFile.begin(),std::bind2nd(std::plus<int>(),1));
1744 int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyh(const std::vector<const DataArrayInt *>& connV, const std::vector<const DataArrayInt *>& connVIndex, const std::vector<const DataArrayInt *>& familiesV,
1745 std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
1746 std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
1749 int nbOfMeshes=connV.size();
1750 connIndexRk24MEDFile.push_back(1);
1751 connIndex4MEDFile.push_back(1);
1753 for(int i=0;i<nbOfMeshes;i++)
1755 const DataArrayInt *conn=connV[i];
1756 const DataArrayInt *connIndex=connVIndex[i];
1757 const DataArrayInt *families=familiesV[i];
1758 int nbOfElem=connIndex->getNbOfElems()-1;
1759 const int *connPtr=conn->getConstPointer();
1760 const int *connIdxPtr=connIndex->getConstPointer();
1761 const int *famPtr=0;
1763 famPtr=families->getConstPointer();
1764 for(int ii=0;ii<nbOfElem;ii++)
1766 int delta=connIdxPtr[1]-connIdxPtr[0];
1767 if(*connPtr==INTERP_KERNEL::NORM_POLYHED)
1769 int nbOfFacesOfPolyh=std::count(connPtr+1,connPtr+delta,-1)+1;
1770 const int *work=connPtr+1;
1771 while(work!=connPtr+delta)
1773 const int *end=std::find(work,connPtr+delta,-1);
1774 conn4MEDFile.insert(conn4MEDFile.end(),work,end);
1775 connIndex4MEDFile.push_back(connIndex4MEDFile.back()+std::distance(work,end));
1776 if(end==connPtr+delta)
1781 connIndexRk24MEDFile.push_back(connIndexRk24MEDFile.back()+nbOfFacesOfPolyh);
1783 fam4MEDFile.push_back(famPtr[ii]);
1784 renumber.push_back(ii+1+renumOffset);
1790 renumOffset+=nbOfElem;
1792 std::transform(conn4MEDFile.begin(),conn4MEDFile.end(),conn4MEDFile.begin(),std::bind2nd(std::plus<int>(),1));
1797 * This method builds a sub set of connectivity for a given type 'type'.
1798 * @param conn input containing connectivity with MEDCoupling format.
1799 * @param connIndex input containing connectivity index in MEDCoupling format.
1800 * @param families input containing, if any, the family number of each cells
1801 * @param type input specifying which cell types will be extracted in conn4MEDFile.
1802 * @param conn4MEDFile output containing the connectivity directly understandable by MEDFile; conn4MEDFile has to be empty before this method called.
1803 * @param connIndex4MEDFile output containing index connectivity understandable by MEDFile; only used by polygons and polyhedrons (it is face nodal connec).
1804 * @param connIndexRk24MEDFile output containing index of rank 2 understandable by MEDFile; only used by polyhedrons.
1805 * @param fam4MEDFile output containing families id of cells whose type is 'type'.
1806 * @return nb of elements extracted.
1808 int MEDLoaderNS::buildMEDSubConnectivityOfOneType(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
1809 INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile,
1810 std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
1813 const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::GetCellModel(type);
1814 if(!cellMod.isDynamic())
1815 return buildMEDSubConnectivityOfOneTypeStaticTypes(conn,connIndex,families,type,conn4MEDFile,fam4MEDFile,renumber);
1818 if(type==INTERP_KERNEL::NORM_POLYGON)
1819 return buildMEDSubConnectivityOfOneTypesPolyg(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,fam4MEDFile,renumber);
1821 return buildMEDSubConnectivityOfOneTypesPolyh(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,connIndexRk24MEDFile,fam4MEDFile,renumber);
1826 * @param ids is a in vector containing families ids whose cells have to be kept. If empty all cells are kept.
1827 * @param typesToKeep is a in vector that indicates which types to keep after dimension filtering.
1828 * @param meshDimExtract out parameter that gives the mesh dimension.
1829 * @param cellRenum out parameter that specifies the renumbering (if !=0) of cells in file.
1831 MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<int>& ids,
1832 const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception)
1834 if(meshDimRelToMax>0)
1835 throw INTERP_KERNEL::Exception("meshDimRelToMax must be <=0 !");
1836 //Extraction data from MED file.
1837 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1838 std::string trueMeshName;
1839 med_int mid=getIdFromMeshName(fid,meshName,trueMeshName);
1840 DataArrayDouble *coords=0;
1841 std::list<MEDLoader::MEDConnOfOneElemType> conn;
1843 readUMeshDataInMedFile(fid,mid,coords,conn,descr);
1844 meshDimExtract=MEDLoaderNS::calculateHighestMeshDim<MEDLoader::MEDConnOfOneElemType>(conn);
1845 meshDimExtract=meshDimExtract+meshDimRelToMax;
1846 MEDLoaderNS::keepSpecifiedMeshDim<MEDLoader::MEDConnOfOneElemType>(conn,meshDimExtract);
1847 MEDLoaderNS::keepTypes<MEDLoader::MEDConnOfOneElemType>(conn,typesToKeep);
1849 //Put data in returned data structure.
1850 MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
1851 ret->setName(trueMeshName.c_str());
1852 ret->setDescription(descr.c_str());
1853 ret->setMeshDimension(meshDimExtract);
1855 ret->setCoords(coords);
1858 DataArrayInt *connArr,*connIndexArr;
1859 tradMEDFileCoreFrmt2MEDCouplingUMesh(conn,ids,connArr,connIndexArr,cellRenum);
1860 ret->setConnectivity(connArr,connIndexArr);
1865 connIndexArr->decrRef();
1866 releaseMEDFileCoreFrmt<MEDLoader::MEDConnOfOneElemType>(conn);
1870 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char *fileName, ParaMEDMEM::TypeOfField typeOfOutField, unsigned meshDim, const int *cellRenum, const ParaMEDMEM::MEDCouplingUMesh *mesh,
1871 const std::vector<std::string>& infos, const char *fieldName, int iteration, int order, double time,
1872 std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerCellType) throw(INTERP_KERNEL::Exception)
1874 if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
1875 MEDLoaderNS::keepSpecifiedMeshDim<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType,meshDim);
1876 if(fieldPerCellType.empty())
1878 std::ostringstream oss; oss << "Error on reading file \"" << fileName << "\" meshName=\"" << mesh->getName();
1879 oss << std::endl << "FieldName=\"" << fieldName << "\" (iteration=" << iteration << ",order=" << order << ")" << std::endl;
1880 if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
1881 oss << "Request for cell field, maybe it is an ON_NODES field ?";
1883 oss << "Request for a node field, maybe it is an ON_CELLS field ?";
1884 throw INTERP_KERNEL::Exception(oss.str().c_str());
1887 ParaMEDMEM::MEDCouplingUMesh *newMesh=0;
1888 std::string mName(mesh->getName());
1889 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
1891 const std::vector<int>& cellIds=(*iter).getCellIdPerType();
1892 if(!cellIds.empty())
1894 std::vector<int> ci(cellIds.size());
1895 std::transform(cellIds.begin(),cellIds.end(),ci.begin(),std::bind2nd(std::plus<int>(),-1));
1896 ParaMEDMEM::MEDCouplingUMesh *mesh2=0;
1897 if(typeOfOutField==ON_CELLS)
1900 mesh2=newMesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size());
1902 mesh2=mesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size());
1904 else if(typeOfOutField==ON_NODES)
1906 DataArrayInt *da=0,*da2=0;
1909 if((int)ci.size()!=newMesh->getNumberOfNodes())
1911 da=newMesh->getCellIdsFullyIncludedInNodeIds(&ci[0],&ci[ci.size()]);
1912 mesh2=dynamic_cast<MEDCouplingUMesh *>(newMesh->buildPartAndReduceNodes(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems(),da2));
1917 if((int)ci.size()!=mesh->getNumberOfNodes())
1919 da=mesh->getCellIdsFullyIncludedInNodeIds(&ci[0],&ci[ci.size()]);
1920 mesh2=dynamic_cast<MEDCouplingUMesh *>(mesh->buildPartAndReduceNodes(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems(),da2));
1922 int nnodes=mesh2->getNumberOfNodes();
1923 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=DataArrayInt::New();
1924 const int *da2Ptr=da2->getConstPointer();
1925 da3->alloc(nnodes,1);
1926 int *da3Ptr=da3->getPointer();
1927 for(int i=0;i<(int)ci.size();i++)
1929 int val=da2Ptr[ci[i]];
1933 mesh2->renumberNodes(da3->getConstPointer(),nnodes);
1937 mesh2=mesh->clone(true);
1938 da=DataArrayInt::New();
1939 da->alloc((int)ci.size(),1);
1940 std::copy(ci.begin(),ci.end(),da->getPointer());
1941 da2=da->invertArrayO2N2N2O(ci.size());
1942 mesh2->renumberNodes(da2->getConstPointer(),(int)ci.size());
1956 ParaMEDMEM::MEDCouplingFieldDouble *ret=ParaMEDMEM::MEDCouplingFieldDouble::New(typeOfOutField,ONE_TIME);
1957 ret->setName(fieldName);
1958 ret->setTime(time,iteration,order);
1961 newMesh->setName(mName.c_str());//retrieving mesh name to avoid renaming due to mesh restriction in case of profile.
1962 ret->setMesh(newMesh);
1967 ParaMEDMEM::DataArrayDouble *arr=buildArrayFromRawData(fieldPerCellType,infos);
1971 if(typeOfOutField==ON_GAUSS_PT)
1972 fillGaussDataOnField(fileName,fieldPerCellType,ret);
1974 ret->renumberCellsWithoutMesh(cellRenum,true);
1978 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order,
1979 ParaMEDMEM::TypeOfField typeOfOutField) throw(INTERP_KERNEL::Exception)
1981 std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType;
1983 std::vector<std::string> infos;
1984 readFieldDoubleDataInMedFile(fileName,meshName,fieldName,iteration,order,typeOfOutField,fieldPerCellType,time,infos);
1985 std::vector<int> familiesToKeep;
1986 std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
1987 if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
1988 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
1989 typesToKeep.push_back((*iter).getType());
1992 if(fieldPerCellType.empty())
1994 std::ostringstream oss; oss << "Error on reading file \"" << fileName << "\" meshName=\"" << meshName << "\" meshDimRelToMax=" << meshDimRelToMax;
1995 oss << std::endl << "FieldName=\"" << fieldName << "\" (iteration=" << iteration << ",order=" << order << ")" << std::endl;
1996 if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
1997 oss << "Request for cell field, maybe it is a node instead or by changing meshDimRelToMax ?";
1999 oss << "Request for a node field, maybe it is a cell field instead ?";
2000 throw INTERP_KERNEL::Exception(oss.str().c_str());
2002 MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingUMesh> mesh=readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
2003 ParaMEDMEM::MEDCouplingFieldDouble *ret=readFieldDoubleLev2(fileName,typeOfOutField,meshDim,cellRenum,mesh,infos,fieldName,iteration,order,time,fieldPerCellType);
2005 mesh->renumberCells(cellRenum,true);
2007 delete [] cellRenum;
2008 releaseMEDFileCoreFrmt<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType);
2014 MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
2016 CheckFileForRead(fileName);
2017 std::vector<int> familiesToKeep;
2018 std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2021 ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
2024 ret->renumberCells(cellRenum,true);
2025 delete [] cellRenum;
2030 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
2032 CheckFileForRead(fileName);
2033 std::vector<int> familiesToKeep;
2034 std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2037 ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,0,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
2040 ret->renumberCells(cellRenum,true);
2041 delete [] cellRenum;
2046 int MEDLoader::ReadUMeshDimFromFile(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
2048 CheckFileForRead(fileName);
2049 std::vector<int> poss;
2050 return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
2053 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception)
2055 CheckFileForRead(fileName);
2056 std::vector<int> familiesToKeep=MEDLoaderNS::getIdsFromFamilies(fileName,meshName,fams);
2057 std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2060 ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
2062 ret->setName(fams.back().c_str());
2065 ret->renumberCells(cellRenum,true);
2066 delete [] cellRenum;
2071 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception)
2073 CheckFileForRead(fileName);
2074 std::vector<int> familiesToKeep=MEDLoaderNS::getIdsFromGroups(fileName,meshName,grps);
2075 std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2078 ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
2080 ret->setName(grps.back().c_str());
2083 ret->renumberCells(cellRenum,true);
2084 delete [] cellRenum;
2089 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)
2091 CheckFileForRead(fileName);
2095 return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
2097 return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
2099 return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
2101 return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
2103 throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
2107 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsOnSameMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
2108 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
2111 return std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>();
2112 CheckFileForRead(fileName);
2113 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> ret(its.size());
2116 //Retrieving mesh of rank 0 and field on rank 0 too.
2117 std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType;
2119 std::vector<std::string> infos;
2120 MEDLoaderNS::readFieldDoubleDataInMedFile(fileName,meshName,fieldName,its[0].first,its[0].second,type,fieldPerCellType,time,infos);
2121 std::vector<int> familiesToKeep;
2122 std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
2123 if(type==ON_CELLS || type==ON_GAUSS_PT || type==ON_GAUSS_NE)
2124 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
2125 typesToKeep.push_back((*iter).getType());
2128 MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingUMesh> m1=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
2129 ret[0]=MEDLoaderNS::readFieldDoubleLev2(fileName,type,meshDim,cellRenum,m1,infos,fieldName,its[0].first,its[0].second,time,fieldPerCellType);
2131 m1->renumberCells(cellRenum,true);
2132 MEDLoaderNS::releaseMEDFileCoreFrmt<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType);
2134 for(int itId=1;itId<(int)its.size();itId++)
2136 std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType2;
2138 std::vector<std::string> infoss;
2139 MEDLoaderNS::readFieldDoubleDataInMedFile(fileName,meshName,fieldName,its[itId].first,its[itId].second,type,fieldPerCellType2,timmee,infoss);
2140 ret[itId]=MEDLoaderNS::readFieldDoubleLev2(fileName,type,meshDim,cellRenum,m1,infoss,fieldName,its[itId].first,its[itId].second,timmee,fieldPerCellType2);
2142 MEDLoaderNS::releaseMEDFileCoreFrmt<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType2);
2144 delete [] cellRenum;
2148 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsCellOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
2149 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
2151 return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
2154 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsNodeOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
2155 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
2157 return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
2160 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
2161 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
2163 return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
2166 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussNEOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
2167 const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
2169 return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
2172 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
2174 return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_CELLS);
2177 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
2179 return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_NODES);
2182 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
2184 return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_GAUSS_PT);
2187 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
2189 return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_GAUSS_NE);
2193 * @param families input parameter that specifies the field on int on each cells of 'mesh'.
2194 * @param isRenumbering output parameter that specifies if a renumbering of mesh has been needed.
2196 void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& mesh, const std::vector<const DataArrayInt *>& families, bool forceFromScratch, bool &isRenumbering)
2198 med_idt fid=MEDfileOpen(fileName,forceFromScratch?MED_ACC_CREAT:MED_ACC_RDWR);
2199 std::string meshName(mesh[0]->getName());
2203 throw INTERP_KERNEL::Exception("MEDCouplingMesh must have a not null name !");
2205 isRenumbering=false;
2206 bool isFamilies=true;
2207 std::vector<const DataArrayInt *> conn;
2208 std::vector<const DataArrayInt *> connIndex;
2209 std::set<INTERP_KERNEL::NormalizedCellType> allTypes;
2210 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=mesh.begin();iter!=mesh.end();iter++)
2212 isRenumbering|=!(*iter)->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
2213 isFamilies&=(families[std::distance(mesh.begin(),iter)]!=0);
2214 conn.push_back((*iter)->getNodalConnectivity());
2215 connIndex.push_back((*iter)->getNodalConnectivityIndex());
2216 const std::set<INTERP_KERNEL::NormalizedCellType>& curTypes=(*iter)->getAllTypes();
2217 allTypes.insert(curTypes.begin(),curTypes.end());
2219 INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2220 INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
2221 MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_NAME_SIZE,maa,MEDLoader::_TOO_LONG_STR);
2222 MEDLoaderBase::safeStrCpy(mesh[0]->getDescription(),MED_COMMENT_SIZE,desc,MEDLoader::_TOO_LONG_STR);
2223 const int spaceDim=mesh[0]->getSpaceDimension();
2224 const int meshDim=mesh[0]->getMeshDimension();
2225 const DataArrayDouble *arr=mesh[0]->getCoords();
2226 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
2227 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
2228 for(int i=0;i<spaceDim;i++)
2230 std::string info=arr->getInfoOnComponent(i);
2232 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
2233 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
2234 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
2236 MEDmeshCr(fid,maa,spaceDim,meshDim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
2237 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=mesh.begin();iter!=mesh.end();iter++)
2239 for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
2241 med_geometry_type curMedType=typmai[i];
2242 INTERP_KERNEL::NormalizedCellType curType=typmai2[i];
2243 if(allTypes.find(curType)!=allTypes.end())
2245 std::vector<int> medConn;
2246 std::vector<int> medConnIndex;
2247 std::vector<int> medConnIndex2;
2248 std::vector<int> fam;
2249 std::vector<int> renumber;
2250 int nbOfElt=MEDLoaderNS::buildMEDSubConnectivityOfOneType(conn,connIndex,families,curType,medConn,medConnIndex,medConnIndex2,fam,renumber);
2251 if(curMedType!=MED_POLYGON && curMedType!=MED_POLYHEDRON)
2252 MEDmeshElementConnectivityWr(fid,maa,-1,-1,0.,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,nbOfElt,&medConn[0]);
2255 if(curMedType==MED_POLYGON)
2256 MEDmeshPolygonWr(fid,maa,-1,-1,0.,MED_CELL,MED_NODAL,medConnIndex.size(),&medConnIndex[0],&medConn[0]);
2257 if(curMedType==MED_POLYHEDRON)
2259 MEDmeshPolyhedronWr(fid,maa,-1,-1,0.,MED_CELL,MED_NODAL,medConnIndex2.size(),&medConnIndex2[0],medConnIndex.size(),&medConnIndex[0],
2264 MEDmeshEntityFamilyNumberWr(fid,maa,-1,-1,MED_CELL,curMedType,nbOfElt,&fam[0]);
2266 MEDmeshEntityNumberWr(fid,maa,-1,-1,MED_CELL,curMedType,nbOfElt,&renumber[0]);
2270 char familyName[MED_NAME_SIZE+1];
2271 std::fill(familyName,familyName+MED_NAME_SIZE+1,'\0');
2272 const char DftFamilyName[]="DftFamily";
2273 std::copy(DftFamilyName,DftFamilyName+sizeof(DftFamilyName),familyName);
2274 MEDfamilyCr(fid,maa,familyName,0,0,0);
2276 MEDmeshNodeCoordinateWr(fid,maa,-1,-1,0.,MED_FULL_INTERLACE,mesh[0]->getNumberOfNodes(),arr->getConstPointer());
2281 * In this method meshes are assumed to shared the same coords.
2282 * This method makes the assumption that 'meshes' is not empty, no check on that is done (responsability of the caller)
2284 void MEDLoaderNS::writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool forceFromScratch)
2286 std::string meshNameCpp(meshName);
2287 INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2288 MEDLoaderBase::safeStrCpy(meshName,MED_NAME_SIZE,maa,MEDLoader::_TOO_LONG_STR);
2290 throw INTERP_KERNEL::Exception("writeUMeshesPartitionDirectly : Invalid meshName : Must be different from \"\" !");
2291 std::vector< DataArrayInt * > corr;
2292 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=ParaMEDMEM::MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
2293 m->setName(meshName);
2294 std::vector< std::vector<int> > fidsOfGroups;
2295 std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
2296 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=DataArrayInt::MakePartition(corr2,m->getNumberOfCells(),fidsOfGroups);
2297 for(std::vector< DataArrayInt * >::iterator it=corr.begin();it!=corr.end();it++)
2300 std::vector<const MEDCouplingUMesh *> mv(1); mv[0]=m;
2301 std::vector<const DataArrayInt *> famv(1); famv[0]=arr2;
2302 writeUMeshesDirectly(fileName,mv,famv,forceFromScratch,isRenumbering);
2303 // families creation
2304 std::set<int> familyIds;
2305 for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGroups.begin();it1!=fidsOfGroups.end();it1++)
2306 for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
2307 familyIds.insert(*it2);
2308 std::vector< std::vector<int> > gidsOfFamilies(familyIds.size());
2310 for(std::set<int>::const_iterator it=familyIds.begin();it!=familyIds.end();it++,fid++)
2313 for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGroups.begin();it1!=fidsOfGroups.end();it1++,gid++)
2314 for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
2316 gidsOfFamilies[fid].push_back(gid);
2319 med_idt fid2=MEDfileOpen(fileName,MED_ACC_RDWR);
2320 for(std::set<int>::const_iterator it=familyIds.begin();it!=familyIds.end();it++,fid++)
2322 int ngro=gidsOfFamilies[fid].size();
2323 INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
2324 for(int i=0;i<ngro;i++)
2325 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
2326 std::ostringstream oss; oss << "Family_" << *it;
2327 INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2328 MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,famName,MEDLoader::_TOO_LONG_STR);
2329 MEDfamilyCr(fid2,maa,famName,*it,ngro,groName);
2335 * This method makes the assumption that f->getMesh() nodes are fully included in already written mesh in 'fileName'.
2336 * @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.
2338 void MEDLoaderNS::appendNodeProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshNodeIds)
2342 INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2343 MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
2344 med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
2345 int nbOfNodes=f->getMesh()->getNumberOfNodes();
2346 const double *pt=f->getArray()->getConstPointer();
2347 INTERP_KERNEL::AutoPtr<int> profile=new int[nbOfNodes];
2348 std::ostringstream oss; oss << "Pfln" << f->getName();
2349 INTERP_KERNEL::AutoPtr<char> profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2350 MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR);
2351 std::transform(thisMeshNodeIds,thisMeshNodeIds+nbOfNodes,(int *)profile,std::bind2nd(std::plus<int>(),1));
2352 MEDprofileWr(fid,profileName,nbOfNodes,profile);
2353 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);
2358 * This method makes the assumption that f->getMesh() cells are fully included in already written mesh in 'fileName'.
2359 * @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.
2361 void MEDLoaderNS::appendCellProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIdsPerType)
2365 int nbComp=f->getNumberOfComponents();
2366 med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
2367 std::list<MEDLoader::MEDFieldDoublePerCellType> split;
2368 prepareCellFieldDoubleForWriting(f,thisMeshCellIdsPerType,split);
2369 const double *pt=f->getArray()->getConstPointer();
2371 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
2373 INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2374 MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
2375 INTERP_KERNEL::AutoPtr<char> profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2376 std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++;
2377 MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR);
2378 const std::vector<int>& ids=(*iter).getCellIdPerType();
2379 int *profile=new int [ids.size()];
2380 std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus<int>(),1));
2381 MEDprofileWr(fid,profileName,ids.size(),profile);
2383 MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,profileName,
2384 MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt);
2385 pt+=(*iter).getNbOfTuple()*nbComp;
2390 void MEDLoaderNS::appendNodeElementProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIdsPerType)
2394 int nbComp=f->getNumberOfComponents();
2395 med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
2396 std::list<MEDLoader::MEDFieldDoublePerCellType> split;
2397 prepareCellFieldDoubleForWriting(f,thisMeshCellIdsPerType,split);
2398 const double *pt=f->getArray()->getConstPointer();
2400 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
2402 INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2403 MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
2404 INTERP_KERNEL::AutoPtr<char> profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2405 std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++;
2406 MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR);
2407 const std::vector<int>& ids=(*iter).getCellIdPerType();
2408 int *profile=new int [ids.size()];
2409 std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus<int>(),1));
2410 MEDprofileWr(fid,profileName,ids.size(),profile);
2412 int nbPtPerCell=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getNumberOfNodes();
2413 int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType());
2414 int nbOfValues=nbPtPerCell*nbOfEntity;
2415 MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE_ELEMENT,typmai3[(int)(*iter).getType()],
2416 MED_COMPACT_PFLMODE,profileName,
2417 MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,
2418 nbOfEntity,(const unsigned char*)pt);
2419 pt+=nbOfValues*nbComp;
2425 * This method performs the classical job for fields before any values setting.
2427 med_idt MEDLoaderNS::appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, med_int& numdt, med_int& numo, med_float& dt)
2429 std::string fieldName(f->getName());
2430 if(fieldName.empty())
2431 throw INTERP_KERNEL::Exception("MEDLoaderNS::appendFieldSimpleAtt : Trying to store a field with no name ! MED file format requires a NON EMPTY field name !");
2432 med_idt fid=MEDfileOpen(fileName,MED_ACC_RDWR);
2433 int nbComp=f->getNumberOfComponents();
2434 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
2435 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
2436 for(int i=0;i<nbComp;i++)
2438 std::string info=f->getArray()->getInfoOnComponent(i);
2440 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
2441 MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);
2442 MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);
2444 INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
2445 INTERP_KERNEL::AutoPtr<char> maaname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2446 INTERP_KERNEL::AutoPtr<char> fname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2447 MEDLoaderBase::safeStrCpy(f->getName(),MED_NAME_SIZE,fname,MEDLoader::_TOO_LONG_STR);
2448 MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,maaname,MEDLoader::_TOO_LONG_STR);
2449 MEDLoaderBase::safeStrCpy(f->getTimeUnit(),MED_SNAME_SIZE,dt_unit,MEDLoader::_TOO_LONG_STR);
2450 MEDfieldCr(fid,fname,MED_FLOAT64,nbComp,comp,unit,dt_unit,maaname);
2451 ParaMEDMEM::TypeOfTimeDiscretization td=f->getTimeDiscretization();
2452 if(td==ParaMEDMEM::NO_TIME)
2454 numdt=MED_NO_DT; numo=MED_NO_IT; dt=0.0;
2456 else if(td==ParaMEDMEM::ONE_TIME)
2459 double tmp0=f->getTime(tmp1,tmp2);
2460 numdt=(med_int)tmp1; numo=(med_int)tmp2;
2466 void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f2)
2471 const ParaMEDMEM::MEDCouplingFieldDouble *f=f2;
2472 const MEDCouplingMesh *mesh=f->getMesh();
2473 const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2475 throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !");
2476 bool renum=!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
2479 ParaMEDMEM::MEDCouplingFieldDouble *f3=f2->clone(true);
2480 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=meshC->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
2481 f3->renumberCells(da->getConstPointer(),false);
2485 int nbComp=f->getNumberOfComponents();
2486 med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
2487 const double *pt=f->getArray()->getConstPointer();
2488 INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2489 MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
2490 switch(f->getTypeOfField())
2492 case ParaMEDMEM::ON_CELLS:
2494 std::list<MEDLoader::MEDFieldDoublePerCellType> split;
2495 prepareCellFieldDoubleForWriting(f,0,split);
2496 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
2498 MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,
2499 MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt);
2500 pt+=(*iter).getNbOfTuple()*nbComp;
2504 case ParaMEDMEM::ON_NODES:
2506 int nbOfTuples=f->getArray()->getNumberOfTuples();
2507 MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE,MED_NONE,MED_COMPACT_PFLMODE,
2508 MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfTuples,(const unsigned char*)pt);
2511 case ParaMEDMEM::ON_GAUSS_PT:
2513 std::list<MEDLoader::MEDFieldDoublePerCellType> split;
2514 prepareCellFieldDoubleForWriting(f,0,split);
2516 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
2518 INTERP_KERNEL::AutoPtr<char> nomGauss=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2519 std::ostringstream oss; oss << "GP_" << f->getName() << idGp++;
2520 MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,nomGauss,MEDLoader::_TOO_LONG_STR);
2521 int id=f->getGaussLocalizationIdOfOneType((*iter).getType());
2522 const MEDCouplingGaussLocalization& gl=f->getGaussLocalization(id);
2523 MEDlocalizationWr(fid,nomGauss,typmai3[(int)(*iter).getType()],mesh->getMeshDimension(),&gl.getRefCoords()[0],MED_FULL_INTERLACE,
2524 gl.getNumberOfGaussPt(),&gl.getGaussCoords()[0],&gl.getWeights()[0],MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT);
2525 int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType());
2526 int nbOfValues=gl.getNumberOfGaussPt()*nbOfEntity;
2527 INTERP_KERNEL::AutoPtr<char> fieldname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2528 MEDLoaderBase::safeStrCpy(f->getName(),MED_NAME_SIZE,fieldname,MEDLoader::_TOO_LONG_STR);
2529 MEDfieldValueWithProfileWr(fid,fieldname,numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,
2530 MED_ALLENTITIES_PROFILE,nomGauss,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt);
2531 pt+=nbOfValues*nbComp;
2535 case ParaMEDMEM::ON_GAUSS_NE:
2537 std::list<MEDLoader::MEDFieldDoublePerCellType> split;
2538 prepareCellFieldDoubleForWriting(f,0,split);
2539 for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
2541 int nbPtPerCell=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getNumberOfNodes();
2542 int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType());
2543 int nbOfValues=nbPtPerCell*nbOfEntity;
2544 MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE_ELEMENT,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,
2545 MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt);
2546 pt+=nbOfValues*nbComp;
2551 throw INTERP_KERNEL::Exception("Not managed this type of FIELD !");
2559 * This method splits field 'f' into types to be ready for writing.
2560 * @param cellIdsPerType this parameter can be 0 if not in profile mode. If it is != 0 this array is of size f->getMesh()->getNumberOfCells().
2562 void MEDLoaderNS::prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *cellIdsPerType, std::list<MEDLoader::MEDFieldDoublePerCellType>& split)
2564 int nbComp=f->getNumberOfComponents();
2565 const MEDCouplingMesh *mesh=f->getMesh();
2566 const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(mesh);
2568 throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !");
2569 if(!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
2570 throw INTERP_KERNEL::Exception("Unstructuded mesh has not consecutive cell types !");
2571 const int *connI=meshC->getNodalConnectivityIndex()->getConstPointer();
2572 const int *conn=meshC->getNodalConnectivity()->getConstPointer();
2573 int nbOfCells=meshC->getNumberOfCells();
2574 INTERP_KERNEL::NormalizedCellType curType;
2575 const int *wCellIdsPT=cellIdsPerType;
2576 for(const int *pt=connI;pt!=connI+nbOfCells;)
2578 curType=(INTERP_KERNEL::NormalizedCellType)conn[*pt];
2579 const int *pt2=std::find_if(pt+1,connI+nbOfCells,ConnReaderML(conn,(int)curType));
2581 split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,0,0));
2584 split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,wCellIdsPT,0));
2585 wCellIdsPT+=std::distance(pt,pt2);
2591 void MEDLoaderNS::writeFieldAndMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch)
2593 f->checkCoherency();
2594 std::string meshName(f->getMesh()->getName());
2595 if(meshName.empty())
2596 throw INTERP_KERNEL::Exception("Trying to write a mesh (f->getMesh()) with no name ! MED file format needs a not empty mesh name !");
2597 std::string fieldName(f->getName());
2598 if(fieldName.empty())
2599 throw INTERP_KERNEL::Exception("Trying to write a field with no name ! MED file format needs a not empty field name !");
2600 MEDCouplingUMesh *mesh=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh()));
2604 std::vector<const MEDCouplingUMesh *> meshV(1); meshV[0]=mesh;
2605 std::vector<const DataArrayInt *> famV(1); famV[0]=0;
2606 writeUMeshesDirectly(fileName,meshV,famV,forceFromScratch,isRenumbering);
2609 MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> f2=f->clone(true);
2610 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=mesh->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
2611 f2->renumberCells(da->getConstPointer(),false);
2612 appendFieldDirectly(fileName,f2);
2615 appendFieldDirectly(fileName,f);
2618 throw INTERP_KERNEL::Exception("The mesh underlying field is not unstructured ! Only unstructured mesh supported for writting now !");
2622 * When called this method expectes that file 'fileName' is already existing and has a mesh with name equal to
2623 * f->getMesh()->getName(). If not the behaviour of this method is not warranted.
2624 * This method reads the corresponding mesh into the file and try to fit it with f->getMesh().
2625 * If it appears that f->getMesh() equals exactly mesh into the file
2627 void MEDLoaderNS::writeFieldTryingToFitExistingMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f)
2629 std::vector<int> poss;
2630 int mDimInFile=MEDLoaderNS::readUMeshDimFromFile(fileName,f->getMesh()->getName(),poss);
2631 int mdim=f->getMesh()->getMeshDimension();
2632 int f2=mdim-mDimInFile;
2633 if(std::find(poss.begin(),poss.end(),f2)==poss.end())
2635 std::ostringstream oss; oss << "Trying to fit with the existing \"" << f->getMesh()->getName() << "mesh in file \"" << fileName;
2636 oss << "\" but meshdimension does not match !";
2637 throw INTERP_KERNEL::Exception(oss.str().c_str());
2639 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=MEDLoader::ReadUMeshFromFile(fileName,f->getMesh()->getName(),f2);
2640 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m2=MEDCouplingUMesh::MergeUMeshes(m,(MEDCouplingUMesh *)f->getMesh());
2641 bool areNodesMerged;
2643 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=m2->mergeNodes(MEDLoader::_EPS_FOR_NODE_COMP,areNodesMerged,newNbOfNodes);
2644 if(!areNodesMerged || newNbOfNodes!=m->getNumberOfNodes())
2646 std::ostringstream oss; oss << "Nodes in already written mesh \"" << f->getMesh()->getName() << "\" in file \"" << fileName << "\" does not fit coordinates of unstructured grid f->getMesh() !";
2647 throw INTERP_KERNEL::Exception(oss.str().c_str());
2649 switch(f->getTypeOfField())
2651 case ParaMEDMEM::ON_CELLS:
2653 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=m2->zipConnectivityTraducer(MEDLoader::_COMP_FOR_CELL);
2654 if(m2->getNumberOfCells()!=m->getNumberOfCells())
2656 std::ostringstream oss1; oss1 << "Cells in already written mesh \"" << f->getMesh()->getName() << "\" in file \"" << fileName << "\" does not fit connectivity of unstructured grid f->getMesh() !";
2657 throw INTERP_KERNEL::Exception(oss1.str().c_str());
2659 da=m2->convertCellArrayPerGeoType(da2);
2660 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->substr(m2->getNumberOfCells());
2661 da2=m2->convertCellArrayPerGeoType(da3);
2662 appendCellProfileField(fileName,f,da2->getConstPointer());
2665 case ParaMEDMEM::ON_GAUSS_NE:
2667 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=m2->zipConnectivityTraducer(MEDLoader::_COMP_FOR_CELL);
2668 if(m2->getNumberOfCells()!=m->getNumberOfCells())
2670 std::ostringstream oss1; oss1 << "Cells in already written mesh \"" << f->getMesh()->getName() << "\" in file \"" << fileName << "\" does not fit connectivity of unstructured grid f->getMesh() !";
2671 throw INTERP_KERNEL::Exception(oss1.str().c_str());
2673 da=m2->convertCellArrayPerGeoType(da2);
2674 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->substr(m2->getNumberOfCells());
2675 da2=m2->convertCellArrayPerGeoType(da3);
2676 appendNodeElementProfileField(fileName,f,da2->getConstPointer());
2679 case ParaMEDMEM::ON_NODES:
2681 appendNodeProfileField(fileName,f,da->getConstPointer()+m->getNumberOfNodes());
2686 throw INTERP_KERNEL::Exception("Not implemented other profile fitting from already written mesh for fields than on NODES and on CELLS.");
2691 void MEDLoader::WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2693 std::string meshName(mesh->getName());
2694 if(meshName.empty())
2695 throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name !");
2696 int status=MEDLoaderBase::getStatusOfFile(fileName);
2698 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2700 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2701 throw INTERP_KERNEL::Exception(oss.str().c_str());
2703 std::vector<const ParaMEDMEM::MEDCouplingUMesh *> meshV(1); meshV[0]=mesh;
2704 std::vector<const ParaMEDMEM::DataArrayInt *> famV(1); famV[0]=0;
2705 if(writeFromScratch)
2707 MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering);
2710 if(status==MEDLoaderBase::NOT_EXIST)
2712 MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering);
2717 std::vector<std::string> meshNames=GetMeshNames(fileName);
2718 if(std::find(meshNames.begin(),meshNames.end(),meshName)==meshNames.end())
2719 MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,false,isRenumbering);
2722 std::ostringstream oss; oss << "File \'" << fileName << "\' already exists and has already a mesh called \"";
2723 oss << meshName << "\" !";
2724 throw INTERP_KERNEL::Exception(oss.str().c_str());
2729 void MEDLoader::WriteUMeshDep(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2731 std::string meshName(mesh->getName());
2732 if(meshName.empty())
2733 throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name !");
2734 int status=MEDLoaderBase::getStatusOfFile(fileName);
2736 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2738 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2739 throw INTERP_KERNEL::Exception(oss.str().c_str());
2741 std::vector<const ParaMEDMEM::MEDCouplingUMesh *> meshV(1); meshV[0]=mesh;
2742 std::vector<const ParaMEDMEM::DataArrayInt *> famV(1); famV[0]=0;
2743 if(writeFromScratch)
2745 MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering);
2748 if(status==MEDLoaderBase::NOT_EXIST)
2750 MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering);
2754 MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,false,isRenumbering);
2757 void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2759 std::string meshName(meshNameC);
2760 if(meshName.empty())
2761 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 !");
2762 int status=MEDLoaderBase::getStatusOfFile(fileName);
2763 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2765 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2766 throw INTERP_KERNEL::Exception(oss.str().c_str());
2769 throw INTERP_KERNEL::Exception("List of meshes must be not empty !");
2770 const DataArrayDouble *coords=meshes.front()->getCoords();
2771 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
2772 if(coords!=(*iter)->getCoords())
2773 throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !");
2774 std::set<std::string> tmp;
2775 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
2777 if(tmp.find((*iter)->getName())==tmp.end())
2778 tmp.insert((*iter)->getName());
2780 throw INTERP_KERNEL::Exception("The names of meshes must be different each other !");
2783 if(writeFromScratch)
2785 MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true);
2788 if(status==MEDLoaderBase::NOT_EXIST)
2790 MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true);
2795 std::vector<std::string> meshNames=GetMeshNames(fileName);
2796 if(std::find(meshNames.begin(),meshNames.end(),meshName)==meshNames.end())
2797 MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,false);
2800 std::ostringstream oss; oss << "File \'" << fileName << "\' already exists and has already a mesh called \"";
2801 oss << meshName << "\" !";
2802 throw INTERP_KERNEL::Exception(oss.str().c_str());
2807 void MEDLoader::WriteUMeshesPartitionDep(const char *fileName, const char *meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2809 std::string meshName(meshNameC);
2810 if(meshName.empty())
2811 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 !");
2812 int status=MEDLoaderBase::getStatusOfFile(fileName);
2813 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2815 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2816 throw INTERP_KERNEL::Exception(oss.str().c_str());
2819 throw INTERP_KERNEL::Exception("List of meshes must be not empty !");
2820 const DataArrayDouble *coords=meshes.front()->getCoords();
2821 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
2822 if(coords!=(*iter)->getCoords())
2823 throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !");
2824 std::set<std::string> tmp;
2825 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
2827 if(tmp.find((*iter)->getName())==tmp.end())
2828 tmp.insert((*iter)->getName());
2830 throw INTERP_KERNEL::Exception("The names of meshes must be different each other !");
2833 if(writeFromScratch)
2835 MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true);
2838 if(status==MEDLoaderBase::NOT_EXIST)
2840 MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true);
2845 MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,false);
2849 void MEDLoader::WriteUMeshes(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2851 int status=MEDLoaderBase::getStatusOfFile(fileName);
2852 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2854 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2855 throw INTERP_KERNEL::Exception(oss.str().c_str());
2858 throw INTERP_KERNEL::Exception("List of meshes must be not empty !");
2859 std::string meshName(meshes[0]->getName());
2860 if(meshName.empty())
2861 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 !");
2862 const DataArrayDouble *coords=meshes.front()->getCoords();
2863 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
2864 if(coords!=(*iter)->getCoords())
2865 throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !");
2867 for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
2869 if(tmp.find((*iter)->getMeshDimension())==tmp.end())
2870 tmp.insert((*iter)->getMeshDimension());
2872 throw INTERP_KERNEL::Exception("The mesh dimension of meshes must be different each other !");
2876 std::vector<const DataArrayInt *> families(meshes.size());
2877 if(writeFromScratch)
2879 MEDLoaderNS::writeUMeshesDirectly(fileName,meshes,families,true,isRenumbering);
2882 if(status==MEDLoaderBase::NOT_EXIST)
2884 MEDLoaderNS::writeUMeshesDirectly(fileName,meshes,families,true,isRenumbering);
2889 MEDLoaderNS::writeUMeshesDirectly(fileName,meshes,families,false,isRenumbering);
2894 void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2896 int status=MEDLoaderBase::getStatusOfFile(fileName);
2897 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2899 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2900 throw INTERP_KERNEL::Exception(oss.str().c_str());
2902 if(writeFromScratch)
2904 MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
2907 if(status==MEDLoaderBase::NOT_EXIST)
2909 MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
2914 std::vector<std::string> meshNames=GetMeshNames(fileName);
2915 std::string fileNameCpp(f->getMesh()->getName());
2916 if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
2917 MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,false);
2919 MEDLoaderNS::writeFieldTryingToFitExistingMesh(fileName,f);
2923 void MEDLoader::WriteFieldDep(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
2925 int status=MEDLoaderBase::getStatusOfFile(fileName);
2926 if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
2928 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
2929 throw INTERP_KERNEL::Exception(oss.str().c_str());
2931 if(writeFromScratch)
2933 MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
2936 if(status==MEDLoaderBase::NOT_EXIST)
2938 MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
2942 MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,false);
2945 void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception)
2947 f->checkCoherency();
2948 int status=MEDLoaderBase::getStatusOfFile(fileName);
2949 if(status!=MEDLoaderBase::EXIST_RW)
2951 std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
2952 throw INTERP_KERNEL::Exception(oss.str().c_str());
2954 MEDLoaderNS::appendFieldDirectly(fileName,f);