1 # include "MEDMEM_Med.hxx"
3 # include "MEDMEM_STRING.hxx"
5 # include "MEDMEM_Mesh.hxx"
6 # include "MEDMEM_Field.hxx"
8 # include "MEDMEM_Exception.hxx"
9 # include "utilities.h"
13 const char * LOC = "MED::MED() : ";
15 MESSAGE(LOC << "Construction...");
19 MED::MED(driverTypes driverType, const string & fileName) {
20 const char * LOC = "MED::MED(driverTypes driverType, const string & fileName) : ";
23 BEGIN_OF(STRING(LOC));
24 current = addDriver(driverType,fileName);
25 _drivers[current]->open();
26 _drivers[current]->readFileStruct();
27 _drivers[current]->close();
35 // ------- Drivers Management Part
37 MED::INSTANCE_DE<MED_MED_DRIVER> MED::inst_med ;
38 //MED::INSTANCE_DE<VTK_DRIVER> MED::inst_vtk ;
40 const MED::INSTANCE * const MED::instances[] = { &MED::inst_med }; //, &MED::inst_vtk } ;
42 int MED::addDriver(driverTypes driverType, const string & fileName="Default File Name.med") {
44 const char * LOC = "MED::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\") : ";
50 driver = instances[driverType]->run(fileName, this) ;
51 _drivers.push_back(driver);
52 current = _drivers.size()-1;
53 // _drivers[current]->set...
60 void MED::rmDriver (int index=0) {
61 const char * LOC = "MED::rmDriver (int index=0): ";
65 //_drivers.erase(&_drivers[index]);
68 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
69 << "The index given is invalid, index must be between 0 and |"
77 void MED::writeFrom (int index=0)
79 const char * LOC = "MED::write (int index=0): ";
82 if (_drivers[index]) {
83 _drivers[index]->open();
84 _drivers[index]->writeFrom();
85 _drivers[index]->close();
87 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
88 << "The index given is invalid, index must be between 0 and |"
96 void MED::write (int index=0)
98 const char * LOC = "MED::writeAll (int index=0): ";
101 if (_drivers[index]) {
102 _drivers[index]->open();
103 _drivers[index]->write();
104 _drivers[index]->close();
107 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
108 << "The index given is invalid, index must be between 0 and |"
116 void MED::readFileStruct (int index=0) {
117 const char * LOC = "MED::readFileStruct (int index=0): ";
120 if (_drivers[index]) {
121 _drivers[index]->open();
122 _drivers[index]->readFileStruct();
123 _drivers[index]->close();
126 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
127 << "The index given is invalid, index must be between 0 and |"
134 // void MED::read (int index=0)
136 // const char * LOC = "MED::read (int index=0): ";
139 // if (_drivers[index])
140 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
141 // << "The index given is invalid, index must be between >0 and < |"
142 // << _drivers.size()-1
146 // _drivers[index]->open();
147 // _drivers[index]->read();
148 // _drivers[index]->close();
154 // ------- End Of Drivers Management Part
156 int MED::getNumberOfMeshes ( void ) const {
158 const char * LOC = "MED::getNumberOfMeshes ( void ) const : ";
161 return _meshes.size();
166 int MED::getNumberOfFields ( void ) const {
168 const char * LOC = "MED::getNumberOfFields ( void ) const : ";
171 // return _meshName.size();
172 return _fields.size(); // we get number of field with different name
177 void MED::getMeshNames ( string * meshNames ) const {
179 const char * LOC = "MED::getMeshNames ( string * ) const : ";
183 if ( ( meshNamesSize = sizeof(meshNames) / sizeof(string *) )
185 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
186 << "Size of parameter meshNames is |"
187 << meshNamesSize << "| and should be |"
188 << _meshes.size() << "| and should be |"
192 // REM : ALLOCATION D'UN TABLEAU DE POINTEURS SUR STRING FAITE PAR LE CLIENT
193 map<MESH_NAME_,MESH*>::const_iterator currentMesh; // ??ITERATEUR CONST SUR UN OBJET NON CONST ??
195 int meshNamesIndex = 0;
197 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
198 meshNames[meshNamesIndex]=(*currentMesh).first;
199 meshNamesIndex++; // CF OPTIMISATION
205 deque<string> MED::getMeshNames () const {
207 const char * LOC = "MED::getMeshNames () const : ";
210 deque<string> meshNames(_meshes.size());
212 map<MESH_NAME_,MESH*>::const_iterator currentMesh; // ??ITERATEUR CONST SUR UN OBJET NON CONST ??
214 int meshNamesIndex = 0;
216 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
217 meshNames[meshNamesIndex]=(*currentMesh).first;
218 meshNamesIndex++; // CF OPTIMISATION
225 MESH * MED::getMesh ( const string & meshName ) const {
227 const char * LOC = "MED::getMesh ( const string & meshName ) const : ";
230 map<MESH_NAME_,MESH*>::const_iterator itMeshes = _meshes.find(meshName);
232 // if ( itMeshes == _meshName.end() )
233 if ( itMeshes == _meshes.end() )
234 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
235 << "There is no known mesh named |"
240 return (*itMeshes).second;
245 MESH * MED::getMesh (const FIELD_ * const field ) const {
247 const char * LOC = "MED::getMesh ( const FIELD * field ) const : ";
250 FIELD_ * f = const_cast< FIELD_* > (field); // Comment faire mieux ?
251 map<FIELD_ *, MESH_NAME_>::const_iterator itMeshName = _meshName.find(f);
253 if ( itMeshName == _meshName.end() )
254 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
255 << "There is no known field associated with |"
256 << field << "| pointer"
260 string meshName = (*itMeshName).second;
261 map<MESH_NAME_,MESH*>::const_iterator itMeshes = _meshes.find(meshName);
262 if ( itMeshes == _meshes.end() )
263 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
264 << "There is no known mesh named |"
265 << meshName << " while it's associated with the found field |"
266 << field << "| pointer"
270 return (*itMeshes).second;
276 void MED::getFieldNames ( string * fieldNames ) const {
278 const char * LOC = "MED::getFieldNames ( string * ) const : ";
281 int fieldNamesSize = sizeof(fieldNames) / sizeof(string *);
283 if ( fieldNamesSize != _fields.size() )
284 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
285 << "Size of parameter fieldNames is |"
286 << fieldNamesSize << "| and should be |"
287 << _fields.size() << "| and should be |"
291 // REM : ALLOCATION D'UN TABLEAU DE POINTEURS SUR STRING FAITE PAR LE CLIENT
292 map<FIELD_NAME_,MAP_DT_IT_>::const_iterator currentField;
294 int fieldNamesIndex = 0;
295 for ( currentField=_fields.begin();currentField != _fields.end(); currentField++ ) {
296 fieldNames[fieldNamesIndex]=(*currentField).first;
297 fieldNamesIndex++; // CF OPTIMISATION
304 deque<string> MED::getFieldNames () const {
306 const char * LOC = "MED::getFieldNames ( ) const : ";
309 deque<string> fieldNames(_fields.size());
311 map<FIELD_NAME_,MAP_DT_IT_>::const_iterator currentField;
313 int fieldNamesIndex = 0;
315 for ( currentField=_fields.begin();currentField != _fields.end(); currentField++ ) {
316 fieldNames[fieldNamesIndex]=(*currentField).first;
317 fieldNamesIndex++; // CF OPTIMISATION
324 deque<DT_IT_> MED::getFieldIteration (const string & fieldName) const {
326 const char * LOC = "MED::getFieldIteration ( const string & ) const : ";
329 map<FIELD_NAME_,MAP_DT_IT_>::const_iterator itFields = _fields.find(fieldName);
331 if ( itFields == _fields.end() )
332 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
333 << "There is no known field named |"
337 // const MAP_DT_IT_ & myIterationMap = const_cast<const MAP_DT_IT_ & > ((*itFields).second);
338 const MAP_DT_IT_ & myIterationMap = (*itFields).second ;
339 MAP_DT_IT_::const_iterator currentIterator ;
341 deque<DT_IT_> Iteration(myIterationMap.size());
343 int iterationIndex = 0;
345 for ( currentIterator=myIterationMap.begin();currentIterator != myIterationMap.end(); currentIterator++ ) {
346 Iteration[iterationIndex]=(*currentIterator).first;
347 iterationIndex++; // CF OPTIMISATION
354 FIELD_ * MED::getField ( const string & fieldName, const int dt=MED_NOPDT, const int it=MED_NOPDT ) const {
356 const char * LOC = "MED::getField ( const string &, const int, const int ) const : ";
359 MESSAGE(LOC << "fieldName = "<<fieldName<<", dt ="<<dt<<", it = "<<it);
366 map<FIELD_NAME_,MAP_DT_IT_>::const_iterator itFields = _fields.find(fieldName);
368 if ( itFields == _fields.end() )
369 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
370 << "There is no known field named |"
375 const MAP_DT_IT_ & map_dtIt = const_cast<const MAP_DT_IT_ & > ((*itFields).second);
376 MAP_DT_IT_::const_iterator itMap_dtIt = map_dtIt.find(dtIt);
378 if ( itMap_dtIt == map_dtIt.end() )
379 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
380 << "There is no (dt,it) |("
381 << dt << "," << it << ")| associated with the found field |"
388 //return _fields[fieldName][dtIt];
389 return (*itMap_dtIt).second;
394 // fiend ostream & MED::operator<<(ostream &os,const MED & med) const {
399 const map<MED_FR::med_entite_maillage,SUPPORT*> & MED::getSupports(const string & meshName) const
401 const char * LOC = "MED::getSupports ( const string ) const : ";
404 map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::const_iterator itSupportOnMesh = _support.find(meshName) ;
406 if ( itSupportOnMesh == _support.end() )
407 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
408 << "There is no support on mesh named |"
413 return (*itSupportOnMesh).second ;
416 SUPPORT * MED::getSupport (const string & meshName,MED_FR::med_entite_maillage entity) const
418 const char * LOC = "MED::getSupport ( const string, MED_FR::med_entite_maillage ) const : ";
421 map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::const_iterator itSupportOnMesh = _support.find(meshName) ;
423 if ( itSupportOnMesh == _support.end() )
424 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
425 << "There is no support on mesh named |"
430 map<MED_FR::med_entite_maillage,SUPPORT *> & SupportOnMesh = (map<MED_FR::med_entite_maillage,SUPPORT *>&) ((*itSupportOnMesh).second) ;
431 map<MED_FR::med_entite_maillage,SUPPORT *>::const_iterator itSupport = SupportOnMesh.find(entity) ;
433 if (itSupport == SupportOnMesh.end() )
434 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
435 << "There is no support on entity "
436 << entity << " in mesh named |"
441 return (*itSupport).second ;
444 void MED::updateSupport ()
447 const char * LOC = "MED::updateSupport () : ";
450 map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::iterator itSupportOnMesh ;
451 for ( itSupportOnMesh=_support.begin();itSupportOnMesh != _support.end(); itSupportOnMesh++ ) {
452 map<MED_FR::med_entite_maillage,SUPPORT *>::iterator itSupport ;
453 for ( itSupport=(*itSupportOnMesh).second.begin();itSupport!=(*itSupportOnMesh).second.end();itSupport++)
455 (*itSupport).second->update() ;
457 catch (MEDEXCEPTION & ex) {
458 // entity not defined in mesh -> we remove support on it !
459 delete (*itSupport).second ;
460 (*itSupportOnMesh).second.erase(itSupport) ; // that's rigth ????
467 void MED::addMesh(const MESH * ptrMesh) throw (MEDEXCEPTION)
469 const char * LOC = "MED::addMesh(const MESH * ptrMesh): ";
471 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "WARNING method not yet implemented"));
474 void MED::addField(const FIELD_ * const ptrField) throw (MEDEXCEPTION)
476 const char * LOC = "MED::addField(const FIELD_ * const ptrField): ";
478 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "WARNING method not yet implemented"));