2 # include "MEDMEM_Med.hxx"
4 # include "MEDMEM_STRING.hxx"
6 # include "MEDMEM_Mesh.hxx"
7 # include "MEDMEM_Field.hxx"
9 # include "MEDMEM_Exception.hxx"
10 # include "utilities.h"
14 const char * LOC = "MED::MED() : ";
16 MESSAGE(LOC << "Construction...");
20 MED::MED(driverTypes driverType, const string & fileName) {
21 const char * LOC = "MED::MED(driverTypes driverType, const string & fileName) : ";
24 BEGIN_OF(STRING(LOC));
25 current = addDriver(driverType,fileName);
26 _drivers[current]->open();
27 _drivers[current]->readFileStruct();
28 _drivers[current]->close();
36 // ------- Drivers Management Part
38 MED::INSTANCE_DE<MED_MED_DRIVER> MED::inst_med ;
39 //MED::INSTANCE_DE<VTK_DRIVER> MED::inst_vtk ;
41 const MED::INSTANCE * const MED::instances[] = { &MED::inst_med }; //, &MED::inst_vtk } ;
43 int MED::addDriver(driverTypes driverType, const string & fileName="Default File Name.med") {
45 const char * LOC = "MED::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\") : ";
51 driver = instances[driverType]->run(fileName, this) ;
52 driver->setId(current);
53 current = _drivers.size()-1;
54 driver->setId(current);
60 /*! Add an existing MESH driver. */
61 int MED::addDriver(GENDRIVER & driver) {
62 const char * LOC = "MED::addDriver(GENDRIVER &) : ";
67 _drivers.push_back(&driver);
68 current = _drivers.size()-1;
69 driver.setId(current);
76 void MED::rmDriver (int index/*=0*/) {
77 const char * LOC = "MED::rmDriver (int index=0): ";
81 //_drivers.erase(&_drivers[index]);
84 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
85 << "The index given is invalid, index must be between 0 and |"
93 void MED::writeFrom (int index/*=0*/)
95 const char * LOC = "MED::write (int index=0): ";
98 if (_drivers[index]) {
99 _drivers[index]->open();
100 _drivers[index]->writeFrom();
101 _drivers[index]->close();
103 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
104 << "The index given is invalid, index must be between 0 and |"
112 void MED::write (int index/*=0*/)
114 const char * LOC = "MED::writeAll (int index=0): ";
117 if (_drivers[index]) {
118 _drivers[index]->open();
119 _drivers[index]->write();
120 _drivers[index]->close();
123 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
124 << "The index given is invalid, index must be between 0 and |"
132 void MED::readFileStruct (int index/*=0*/) {
133 const char * LOC = "MED::readFileStruct (int index=0): ";
136 if (_drivers[index]) {
137 _drivers[index]->open();
138 _drivers[index]->readFileStruct();
139 _drivers[index]->close();
142 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
143 << "The index given is invalid, index must be between 0 and |"
150 // void MED::read (int index=0)
152 // const char * LOC = "MED::read (int index=0): ";
155 // if (_drivers[index])
156 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
157 // << "The index given is invalid, index must be between >0 and < |"
158 // << _drivers.size()-1
162 // _drivers[index]->open();
163 // _drivers[index]->read();
164 // _drivers[index]->close();
170 // ------- End Of Drivers Management Part
172 int MED::getNumberOfMeshes ( void ) const {
174 const char * LOC = "MED::getNumberOfMeshes ( void ) const : ";
177 return _meshes.size();
182 int MED::getNumberOfFields ( void ) const {
184 const char * LOC = "MED::getNumberOfFields ( void ) const : ";
187 // return _meshName.size();
188 return _fields.size(); // we get number of field with different name
193 void MED::getMeshNames ( string * meshNames ) const {
195 const char * LOC = "MED::getMeshNames ( string * ) const : ";
199 if ( ( meshNamesSize = sizeof(meshNames) / sizeof(string *) )
201 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
202 << "Size of parameter meshNames is |"
203 << meshNamesSize << "| and should be |"
204 << _meshes.size() << "| and should be |"
208 // REM : ALLOCATION D'UN TABLEAU DE POINTEURS SUR STRING FAITE PAR LE CLIENT
209 map<MESH_NAME_,MESH*>::const_iterator currentMesh; // ??ITERATEUR CONST SUR UN OBJET NON CONST ??
211 int meshNamesIndex = 0;
213 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
214 meshNames[meshNamesIndex]=(*currentMesh).first;
215 meshNamesIndex++; // CF OPTIMISATION
221 deque<string> MED::getMeshNames () const {
223 const char * LOC = "MED::getMeshNames () const : ";
226 deque<string> meshNames(_meshes.size());
228 map<MESH_NAME_,MESH*>::const_iterator currentMesh; // ??ITERATEUR CONST SUR UN OBJET NON CONST ??
230 int meshNamesIndex = 0;
232 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
233 meshNames[meshNamesIndex]=(*currentMesh).first;
234 meshNamesIndex++; // CF OPTIMISATION
241 MESH * MED::getMesh ( const string & meshName ) const {
243 const char * LOC = "MED::getMesh ( const string & meshName ) const : ";
246 map<MESH_NAME_,MESH*>::const_iterator itMeshes = _meshes.find(meshName);
248 // if ( itMeshes == _meshName.end() )
249 if ( itMeshes == _meshes.end() )
250 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
251 << "There is no known mesh named |"
256 return (*itMeshes).second;
261 MESH * MED::getMesh (const FIELD_ * const field ) const {
263 const char * LOC = "MED::getMesh ( const FIELD * field ) const : ";
266 FIELD_ * f = const_cast< FIELD_* > (field); // Comment faire mieux ?
267 map<FIELD_ *, MESH_NAME_>::const_iterator itMeshName = _meshName.find(f);
269 if ( itMeshName == _meshName.end() )
270 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
271 << "There is no known field associated with |"
272 << field << "| pointer"
276 string meshName = (*itMeshName).second;
277 map<MESH_NAME_,MESH*>::const_iterator itMeshes = _meshes.find(meshName);
278 if ( itMeshes == _meshes.end() )
279 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
280 << "There is no known mesh named |"
281 << meshName << " while it's associated with the found field |"
282 << field << "| pointer"
286 return (*itMeshes).second;
292 void MED::getFieldNames ( string * fieldNames ) const {
294 const char * LOC = "MED::getFieldNames ( string * ) const : ";
297 int fieldNamesSize = sizeof(fieldNames) / sizeof(string *);
299 if ( fieldNamesSize != _fields.size() )
300 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
301 << "Size of parameter fieldNames is |"
302 << fieldNamesSize << "| and should be |"
303 << _fields.size() << "| and should be |"
307 // REM : ALLOCATION D'UN TABLEAU DE POINTEURS SUR STRING FAITE PAR LE CLIENT
308 map<FIELD_NAME_,MAP_DT_IT_>::const_iterator currentField;
310 int fieldNamesIndex = 0;
311 for ( currentField=_fields.begin();currentField != _fields.end(); currentField++ ) {
312 fieldNames[fieldNamesIndex]=(*currentField).first;
313 fieldNamesIndex++; // CF OPTIMISATION
320 deque<string> MED::getFieldNames () const {
322 const char * LOC = "MED::getFieldNames ( ) const : ";
325 deque<string> fieldNames(_fields.size());
327 map<FIELD_NAME_,MAP_DT_IT_>::const_iterator currentField;
329 int fieldNamesIndex = 0;
331 for ( currentField=_fields.begin();currentField != _fields.end(); currentField++ ) {
332 fieldNames[fieldNamesIndex]=(*currentField).first;
333 fieldNamesIndex++; // CF OPTIMISATION
340 deque<DT_IT_> MED::getFieldIteration (const string & fieldName) const {
342 const char * LOC = "MED::getFieldIteration ( const string & ) const : ";
345 map<FIELD_NAME_,MAP_DT_IT_>::const_iterator itFields = _fields.find(fieldName);
347 if ( itFields == _fields.end() )
348 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
349 << "There is no known field named |"
353 // const MAP_DT_IT_ & myIterationMap = const_cast<const MAP_DT_IT_ & > ((*itFields).second);
354 const MAP_DT_IT_ & myIterationMap = (*itFields).second ;
355 MAP_DT_IT_::const_iterator currentIterator ;
357 deque<DT_IT_> Iteration(myIterationMap.size());
359 int iterationIndex = 0;
361 for ( currentIterator=myIterationMap.begin();currentIterator != myIterationMap.end(); currentIterator++ ) {
362 Iteration[iterationIndex]=(*currentIterator).first;
363 iterationIndex++; // CF OPTIMISATION
370 FIELD_ * MED::getField ( const string & fieldName, const int dt=MED_NOPDT, const int it=MED_NOPDT ) const {
372 const char * LOC = "MED::getField ( const string &, const int, const int ) const : ";
375 MESSAGE(LOC << "fieldName = "<<fieldName<<", dt ="<<dt<<", it = "<<it);
382 map<FIELD_NAME_,MAP_DT_IT_>::const_iterator itFields = _fields.find(fieldName);
384 if ( itFields == _fields.end() )
385 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
386 << "There is no known field named |"
391 const MAP_DT_IT_ & map_dtIt = const_cast<const MAP_DT_IT_ & > ((*itFields).second);
392 MAP_DT_IT_::const_iterator itMap_dtIt = map_dtIt.find(dtIt);
394 if ( itMap_dtIt == map_dtIt.end() )
395 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
396 << "There is no (dt,it) |("
397 << dt << "," << it << ")| associated with the found field |"
404 //return _fields[fieldName][dtIt];
405 return (*itMap_dtIt).second;
410 // fiend ostream & MED::operator<<(ostream &os,const MED & med) const {
415 const map<MED_FR::med_entite_maillage,SUPPORT*> & MED::getSupports(const string & meshName) const
417 const char * LOC = "MED::getSupports ( const string ) const : ";
420 map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::const_iterator itSupportOnMesh = _support.find(meshName) ;
422 if ( itSupportOnMesh == _support.end() )
423 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
424 << "There is no support on mesh named |"
429 return (*itSupportOnMesh).second ;
432 SUPPORT * MED::getSupport (const string & meshName,MED_FR::med_entite_maillage entity) const
434 const char * LOC = "MED::getSupport ( const string, MED_FR::med_entite_maillage ) const : ";
437 map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::const_iterator itSupportOnMesh = _support.find(meshName) ;
439 if ( itSupportOnMesh == _support.end() )
440 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
441 << "There is no support on mesh named |"
446 map<MED_FR::med_entite_maillage,SUPPORT *> & SupportOnMesh = (map<MED_FR::med_entite_maillage,SUPPORT *>&) ((*itSupportOnMesh).second) ;
447 map<MED_FR::med_entite_maillage,SUPPORT *>::const_iterator itSupport = SupportOnMesh.find(entity) ;
449 if (itSupport == SupportOnMesh.end() )
450 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
451 << "There is no support on entity "
452 << entity << " in mesh named |"
457 return (*itSupport).second ;
460 void MED::updateSupport ()
463 const char * LOC = "MED::updateSupport () : ";
466 map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::iterator itSupportOnMesh ;
467 for ( itSupportOnMesh=_support.begin();itSupportOnMesh != _support.end(); itSupportOnMesh++ ) {
468 map<MED_FR::med_entite_maillage,SUPPORT *>::iterator itSupport ;
469 for ( itSupport=(*itSupportOnMesh).second.begin();itSupport!=(*itSupportOnMesh).second.end();itSupport++)
471 (*itSupport).second->update() ;
473 catch (MEDEXCEPTION & ex) {
474 // entity not defined in mesh -> we remove support on it !
475 delete (*itSupport).second ;
476 (*itSupportOnMesh).second.erase(itSupport) ; // that's rigth ????
483 void MED::addMesh(const MESH * ptrMesh) throw (MEDEXCEPTION)
485 const char * LOC = "MED::addMesh(const MESH * ptrMesh): ";
487 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "WARNING method not yet implemented"));
490 void MED::addField(const FIELD_ * const ptrField) throw (MEDEXCEPTION)
492 const char * LOC = "MED::addField(const FIELD_ * const ptrField): ";
494 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "WARNING method not yet implemented"));