4 # include "MEDMEM_MedMedDriver.hxx"
6 # include "MEDMEM_DriversDef.hxx"
8 # include "MEDMEM_Mesh.hxx"
9 # include "MEDMEM_Grid.hxx"
10 # include "MEDMEM_Field.hxx"
11 // EN ATTENDANT L'utilisation de MedFieldDriver.hxx ds Field.hxx
12 # include "MEDMEM_MedFieldDriver.hxx"
13 # include "MEDMEM_Med.hxx"
15 # include "MEDMEM_define.hxx"
17 using namespace MED_FR;
19 MED_MED_DRIVER::MED_MED_DRIVER(): GENDRIVER(),
20 _ptrMed((MED * const)MED_NULL),_medIdt(MED_INVALID)
23 MED_MED_DRIVER::MED_MED_DRIVER(const string & fileName, MED * const ptrMed):
24 GENDRIVER(fileName,MED_EN::MED_RDWR), _ptrMed(ptrMed), _medIdt(MED_INVALID)
26 _ptrMed->addDriver(*this); // The specific MED driver id is set within the addDriver method.
29 MED_MED_DRIVER::MED_MED_DRIVER(const string & fileName,
31 MED_EN::med_mode_acces accessMode):
32 GENDRIVER(fileName,accessMode), _ptrMed(ptrMed), _medIdt(MED_INVALID)
35 //REM : As t'on besoin du champ _status : _medIdt <-> _status ? Oui
37 MED_MED_DRIVER::MED_MED_DRIVER(const MED_MED_DRIVER & driver):
39 _ptrMed(driver._ptrMed),
44 MED_MED_DRIVER::~MED_MED_DRIVER()
46 MESSAGE("MED_MED_DRIVER::~MED_MED_DRIVER() has been destroyed");
49 // GENDRIVER * MED_MED_DRIVER::copy(void) const
51 // return new MED_MED_DRIVER(*this) ;
53 void MED_MED_DRIVER::read()
56 void MED_MED_DRIVER::readFileStruct()
59 void MED_MED_DRIVER::write() const
62 GENDRIVER * MED_MED_DRIVER::copy(void) const
64 return new MED_MED_DRIVER(*this) ;
66 void MED_MED_DRIVER::writeFrom() const
72 void MED_MED_DRIVER::open()
76 const char * LOC ="MED_MED_DRIVER::open() : ";
79 // REFLECHIR SUR CE TEST PAR RAPPORT A L'OUVERTURE/FERMETURE
80 // if ( _medIdt != MED_INVALID )
81 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
82 // << "_medIdt is already in use, please close the file |"
83 // << _fileName << "| before calling open()"
87 // if ( _status != MED_CLOSED )
88 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
89 // << "_status is closed, please close the file |"
90 // << _fileName << "| before calling open()"
94 if ( _fileName == "" )
95 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
96 << "_fileName is |\"\"|, please set a correct fileName before calling open()"
100 MESSAGE(LOC<<"_fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode);
101 _medIdt = MEDouvrir( (const_cast <char *> (_fileName.c_str())), (MED_FR::med_mode_acces) _accessMode);
102 MESSAGE(LOC<<" _medIdt = "<<_medIdt);
107 _status = MED_CLOSED;
108 _medIdt = MED_INVALID;
109 throw MED_EXCEPTION (LOCALIZED( STRING(LOC)
110 << "Can't open |" << _fileName
111 << "|, _medIdt : " << _medIdt
120 void MED_MED_DRIVER::close()
122 MED_FR::med_int err = 0;
123 const char * LOC = "MED_MED_DRIVER::close() : ";
126 // if ( _status == MED_CLOSED)
127 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << ": the file |"
128 // << _fileName << "| is already closed"
132 // if ( _medIdt == MED_INVALID )
133 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "_medIdt invalid, but the file |"
134 // << _fileName << "| seems to be openned !"
138 if ( _medIdt != MED_INVALID )
139 err=MEDfermer(_medIdt);
141 // if (err != MED_VALID)
142 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "the file |"
143 // << _fileName << "| couldn't be closed"
147 _status = MED_CLOSED;
148 _medIdt = MED_INVALID;
154 // ------------- Read Only Part --------------
156 MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER():MED_MED_DRIVER()
160 MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const string & fileName, MED * const ptrMed):
161 MED_MED_DRIVER(fileName,ptrMed,MED_EN::MED_RDONLY)
163 MESSAGE("MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const string & fileName, MED * const ptrMed) Constructeur read only");
166 MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const MED_MED_RDONLY_DRIVER & driver):
167 MED_MED_DRIVER(driver)
171 MED_MED_RDONLY_DRIVER::~MED_MED_RDONLY_DRIVER()
173 MESSAGE("MED_MED_RDONLY_DRIVER::~MED_MED_RDONLY_DRIVER() has been destroyed");
176 GENDRIVER * MED_MED_RDONLY_DRIVER::copy(void) const
178 return new MED_MED_RDONLY_DRIVER(*this) ;
181 void MED_MED_RDONLY_DRIVER::readFileStruct( void )
184 const char * LOC = "MED_MED_DRIVER::readFileStruct() : ";
189 if ( _medIdt == MED_INVALID )
190 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
191 << "_medIdt is invalid, please open the file |"
192 << _fileName << "| before calling readFileStruct()"
195 // Read number of meshes and their associated name
198 char meshName[MED_TAILLE_NOM+1]="";
201 // MED_MESH_RDWR_DRIVER * ptrDriver; !! UNUSED VARIABLE !!
203 numberOfMeshes = MEDnMaa(_medIdt) ;
204 if ( numberOfMeshes <= 0 )
205 MESSAGE(LOC << "Be careful there is no mesh in file |"<<_fileName<<"| !");
207 MESH_ENTITIES::const_iterator currentEntity;
208 for (i=1;i<=numberOfMeshes;i++) {
210 // find out if the mesh is a Grid
213 MED_FR::med_grid_type type;
215 err = MEDgridInfo (_medIdt, i, &isAGrid, &type);
216 if (err != MED_VALID)
217 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "error in MEDgridInfo()") );
219 err = MEDmaaInfo(_medIdt, i ,meshName, &meshDim) ;
220 if (err != MED_VALID)
221 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << ": can't get information about the mesh n°"
222 << i <<" of the file |" << _fileName << "| !"
225 MESSAGE(LOC<<": Mesh n°"<<i<<" nammed "<<meshName);
228 ptrMesh = new GRID((MED_EN::med_grid_type) type);
230 ptrMesh = new MESH();
232 //MED_MESH_RDWR_DRIVER * _ptrDriver = new MED_MESH_RDWR_DRIVER(_fileName, ptrMesh);
233 MED_EN::med_mode_acces myMode = getAccessMode();
234 MED_MESH_DRIVER * ptrDriver ;
236 case MED_EN::MED_LECT:
237 ptrDriver = new MED_MESH_RDONLY_DRIVER(_fileName, ptrMesh);
239 case MED_EN::MED_REMP:
240 ptrDriver = new MED_MESH_RDWR_DRIVER(_fileName, ptrMesh);
242 case MED_EN::MED_ECRI: // should never append !!
243 ptrDriver = new MED_MESH_RDONLY_DRIVER(_fileName, ptrMesh);
246 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
248 ptrDriver->setId ( getId() );
249 ptrDriver->setMeshName ( meshName );
250 ptrMesh->addDriver(*ptrDriver);
254 _ptrMed->_meshes[meshName] = (MESH *) ptrMesh;
256 _ptrMed->_meshes[meshName] = ptrMesh;
258 ptrMesh->setName(meshName);
262 MESSAGE(LOC<<"is" << (isAGrid ? "" : " NOT") << " a GRID and its name is "<<ptrMesh->getName());
264 // we create all global support (for each entity type :
266 for (currentEntity=meshEntities.begin();currentEntity != meshEntities.end(); currentEntity++) {
267 string supportName="SupportOnAll_" ;
268 supportName+=entNames[(MED_FR::med_entite_maillage)(*currentEntity).first] ;
269 //(_ptrMed->_support)[meshName][(MED_FR::med_entite_maillage)(*currentEntity).first]=new SUPPORT(ptrMesh,supportName,(MED_EN::medEntityMesh) (*currentEntity).first) ;
270 SUPPORT* mySupport = new SUPPORT() ;
271 mySupport->setName(supportName);
272 mySupport->setMesh(ptrMesh);
273 mySupport->setEntity((MED_EN::medEntityMesh) (*currentEntity).first);
274 mySupport->setAll(true);
275 (_ptrMed->_support)[meshName][(MED_FR::med_entite_maillage)(*currentEntity).first] = mySupport ;
276 MESSAGE(LOC<< "The support " << supportName.c_str() << " on entity " << (*currentEntity).first << " is built");
279 MESSAGE(LOC <<"The mesh " <<ptrMesh->getName() << " has " << index << " support(s)");
282 map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::const_iterator const_itSupportOnMesh ;
286 vector<SUPPORT *> vectSupp;
287 for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
288 const_itSupportOnMesh++ )
290 map<MED_FR::med_entite_maillage,SUPPORT *>::const_iterator const_itSupport ;
291 for (const_itSupport=(*const_itSupportOnMesh).second.begin();
292 const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++) index++;
295 MESSAGE(LOC << "In this MED object there is(are) " << index << " support(s):");
297 vectSupp.resize(index);
300 for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
301 const_itSupportOnMesh++ )
303 map<MED_FR::med_entite_maillage,SUPPORT *>::const_iterator const_itSupport ;
304 for (const_itSupport=(*const_itSupportOnMesh).second.begin();
305 const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++)
307 vectSupp[index] = (*const_itSupport).second;
308 SCRUTE(vectSupp[index]);
309 MESSAGE(LOC << "Support number " << index << " is "<< *vectSupp[index]);
317 // Read number of fields, their associated name and their list of (timeStepNumber,iterationNumber)
319 int numberOfFields = 0; //MED_INVALID
320 // char fieldName[MED_TAILLE_NOM+1] = "";
321 char fieldName[MED_TAILLE_NOM+1] ;
322 int numberOfComponents = 0;
323 char * componentName = (char *) MED_NULL;
324 char * unitName = (char *) MED_NULL;
325 // char meshName[MED_TAILLE_NOM+1] = "";
326 char meshName[MED_TAILLE_NOM+1] ;
327 MED_FR::med_type_champ type;
328 MESH * ptrMesh = (MESH *) MED_NULL;
329 FIELD_ * ptrField = (FIELD_ *) MED_NULL;
330 //MED_FIELD_RDWR_DRIVER * ptrDriver = (MED_FIELD_RDWR_DRIVER * ) MED_NULL;
331 GENDRIVER * ptrDriver = (GENDRIVER * ) MED_NULL;
332 SUPPORT * ptrSupport = (SUPPORT * ) MED_NULL;
333 MESH_ENTITIES::const_iterator currentEntity;
334 list<MED_FR::med_geometrie_element>::const_iterator currentGeometry;
335 int NbOfGaussPts = 0;
336 int numberOfTimeSteps = -1;
337 int timeStepNumber = -1;
338 // char timeStepUnit[MED_TAILLE_PNOM]= "";
339 char timeStepUnit[MED_TAILLE_PNOM+1] ;
340 double timeStep = 0.0;
341 int orderNumber = -1; //???init?????
342 map<MESH_NAME_,MESH*> & _meshes = _ptrMed->_meshes;
343 map<FIELD_NAME_,MAP_DT_IT_> & _fields = _ptrMed->_fields;
344 map<FIELD_ *, MESH_NAME_> & _meshName = _ptrMed->_meshName;
345 map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> > & _support = _ptrMed->_support;
348 numberOfFields = MEDnChamp(_medIdt,0) ;
349 if ( numberOfFields <= 0 )
350 MESSAGE(LOC << "Be careful there is no field in file |"<<_fileName<<"| !");
352 for (i=1;i<=numberOfFields;i++) {
354 numberOfComponents = MEDnChamp(_medIdt,i) ;
355 if ( numberOfComponents <= 0 )
356 if (err != MED_VALID)
357 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Be careful there is no compound for field n°"
358 << i << "in file |"<<_fileName<<"| !"));
360 componentName = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;
361 unitName = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;
363 err = MEDchampInfo(_medIdt, i, fieldName, &type, componentName,
364 unitName, numberOfComponents) ;
366 if (err != MED_VALID)
367 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
368 << ": can't get information about the field n°"
369 << i <<" of the file |" << _fileName << "| !"));
371 MESSAGE(LOC << "Field n°"<<i<<" nammed "<< fieldName
372 << " ,component(s) : " << componentName
373 <<" ,unit(s) : " << unitName);
376 // Loop on all (entity type,geometry type) until you find an existing one then
377 // get the (n°dt,n°it) pairs list for the current (field,entity type,geometry type)
378 // We suppose there is the same list whatever the existing (entity type,geometry type) pair
380 for (currentEntity=meshEntities.begin();currentEntity != meshEntities.end(); currentEntity++) {
381 // numberOfTimeSteps MUST be given by MEDchampInfo !!!!!
382 for (currentGeometry = (*currentEntity).second.begin();currentGeometry != (*currentEntity).second.end(); currentGeometry++) {
383 MESSAGE("Field information with Entity,Geom = "<<(*currentEntity).first<<","<<(*currentGeometry));
384 numberOfTimeSteps = MEDnPasdetemps(_medIdt, fieldName,
385 (MED_FR::med_entite_maillage)(*currentEntity).first,
386 (MED_FR::med_geometrie_element) (*currentGeometry) );
387 MESSAGE("Field information 2 : NumberOfTimeStep :"<<numberOfTimeSteps);
388 if ( numberOfTimeSteps > MED_VALID )
389 break ; // There are value for some med_geometrie_element of this med_entite_maillage.
391 if (numberOfTimeSteps>0) // we have at least one
393 for (currentGeometry = (*currentEntity).second.begin();currentGeometry != (*currentEntity).second.end(); currentGeometry++) {
395 MESSAGE("Field information 3 : Geom : "<<(*currentGeometry));
396 for (j=1;j <= numberOfTimeSteps; j++) {
398 MESSAGE("Field information 4 : time step j = "<<j);
399 err = MEDpasdetempsInfo( _medIdt, fieldName,
400 (MED_FR::med_entite_maillage) (*currentEntity).first,
401 (*currentGeometry),j,
402 meshName, &NbOfGaussPts,
403 &timeStepNumber, timeStepUnit, &timeStep,
405 if (err == MED_VALID) { // we have found for (*currentEntity).first and (*currentGeometry)
407 MESSAGE("Field information 5 ;: NumberOfGaussPoint : "<<NbOfGaussPts<<", timeStepNumber : "<<timeStepNumber);
408 // CORRECT a bug in MEDpasdetempsInfo :
409 // we get a value n'importe quoi in NbOfGaussPts !!!!
411 if (NbOfGaussPts>100)
413 if (timeStepNumber<0)
417 // ATTENTION TRAITER L'EXCEPTION !!!!!!!!!!!!
419 // Il faudra traiter le cas d'un champ qui utilise +sieurs (entity,geom) voir le travail de patrick
420 // Il faudra traiter le cas des profils...
421 // ptrField = new FIELD();
422 // _ptrDriver = new MED_FIELD_RDWR_DRIVER(_fileName, ptrField);
423 // ptrField->addDriver(_ptrDriver);
424 // _fields[fieldName]=ptrField;
426 // Verify meshName is already known
428 map<MESH_NAME_,MESH*>::iterator _meshesIt = _meshes.find(meshName);
429 if ( _meshesIt == _meshes.end() ) {
430 MESSAGE(LOC << "There is no mesh |"
431 << meshName <<"| in the file |"
432 << _fileName <<"|, but |" << meshName <<"| is referenced by field |"
433 << fieldName <<"|, entity : |"
434 << entNames [ (MED_FR::med_entite_maillage) (*currentEntity).first] <<"|, geometric element of type |"
435 << geoNames [ (MED_FR::med_geometrie_element) (*currentGeometry)] <<"|"
437 } // POURQUOI SI JE NE MET PAS DE BLOCK J'AI UN PARSE ERROR : PG : c'est la macro MESSAGE qui fait ca !
439 ptrMesh = _meshes[meshName];
441 ptrSupport = _support[meshName][(MED_FR::med_entite_maillage) (*currentEntity).first];
442 if (NbOfGaussPts != 1)
443 throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<"Number of Gauss Point must be equal to 1 for instance")) ;
445 // init to null to prevent some error if not correctly allocated !
446 ptrField = (FIELD_*)NULL ;
447 ptrDriver = (GENDRIVER*)NULL ;
450 case MED_FR::MED_INT64 :
451 if ( sizeof(MED_FR::med_int) != 8 )
452 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) <<
453 " The Field type of |"
454 << fieldName <<"|, entity : |"
455 << entNames [(MED_FR::med_entite_maillage) (*currentEntity).first] <<"|, geometric element of type |"
456 << geoNames [(MED_FR::med_geometrie_element) (*currentGeometry) ] <<
457 "| is MED_INT64 but size of med_int is not equal to 8 bytes !"
461 case MED_FR::MED_INT32 : {
462 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) <<
463 // "NOT IMPLEMENTED : BUG IN STL !")
465 // ptrField = new FIELD<MED_FR::med_int> ( ptrSupport,numberOfComponents ); // Les valeurs du champ ne doivent pas être lue pour l'instant
467 ptrField = new FIELD<MED_FR::med_int> ( ); // Les valeurs du champ ne doivent pas être lue pour l'instant
468 ((FIELD<MED_FR::med_int>*) ptrField)->setSupport(ptrSupport);
469 ((FIELD<MED_FR::med_int>*) ptrField)->setNumberOfComponents(numberOfComponents);
470 ((FIELD<MED_FR::med_int>*) ptrField)->setName(fieldName) ; //provisoire, pour debug
471 MESSAGE("#### SET NAME in FIELD : "<<fieldName);
473 MED_EN::med_mode_acces myMode = getAccessMode();
475 case MED_EN::MED_LECT:
476 ptrDriver = new MED_FIELD_RDONLY_DRIVER<MED_FR::med_int>(_fileName, (FIELD<MED_FR::med_int> *)ptrField);
478 case MED_EN::MED_REMP:
479 ptrDriver = new MED_FIELD_RDWR_DRIVER<MED_FR::med_int>(_fileName, (FIELD<MED_FR::med_int> *)ptrField);
481 case MED_EN::MED_ECRI: // should never append !!
482 ptrDriver = new MED_FIELD_RDONLY_DRIVER<MED_FR::med_int>(_fileName, (FIELD<MED_FR::med_int> *)ptrField);
485 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
489 case MED_FR::MED_REEL64 : {
490 // ptrField = new FIELD<MED_FR::med_float> ( ptrSupport,numberOfComponents ); // Les valeurs du champ ne doivent pas être lue pour l'instant
491 ptrField = new FIELD<MED_FR::med_float> ( ); // Les valeurs du champ ne doivent pas être lue pour l'instant
492 ((FIELD<MED_FR::med_float>*) ptrField)->setSupport(ptrSupport);
493 ((FIELD<MED_FR::med_float>*) ptrField)->setNumberOfComponents(numberOfComponents);
494 ((FIELD<MED_FR::med_float>*) ptrField)->setName(fieldName) ; //provisoire, pour debug
495 MESSAGE("#### SET NAME in FIELD : "<<fieldName);
497 MED_EN::med_mode_acces myMode = getAccessMode();
499 case MED_EN::MED_LECT:
500 ptrDriver = new MED_FIELD_RDONLY_DRIVER<MED_FR::med_float>(_fileName, (FIELD<MED_FR::med_float> *)ptrField);
502 case MED_EN::MED_REMP:
503 ptrDriver = new MED_FIELD_RDWR_DRIVER<MED_FR::med_float>(_fileName, (FIELD<MED_FR::med_float> *)ptrField);
505 case MED_EN::MED_ECRI: // should never append !!
506 ptrDriver = new MED_FIELD_RDONLY_DRIVER<MED_FR::med_float>(_fileName, (FIELD<MED_FR::med_float> *)ptrField);
509 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
514 if ( numberOfTimeSteps > 1)
515 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) <<
516 " The Field type of |"
517 << fieldName <<"|, entity : |"
518 << entNames [(MED_FR::med_entite_maillage) (*currentEntity).first]
519 <<"|, geometric element of type |"
520 << geoNames [(MED_FR::med_geometrie_element) (*currentGeometry)]
521 <<"| is neither MED_INT, MED_INT32, MED_INT64 nor MED_REEL64 !"
527 ptrField->setValueType((MED_EN::med_type_champ) type) ; // need to write field !
529 MESSAGE("timeStepNumber :"<<timeStepNumber<<",orderNumber :"<<orderNumber);
530 ptrField->setIterationNumber ( timeStepNumber); // A ajouter dans la classe FIELD
531 ptrField->setOrderNumber ( orderNumber);
532 ptrField->setTime ( timeStep);
534 // Create a driver for this (field n°dt,n°it)
535 ptrDriver->setId ( getId() );
536 MESSAGE("###### ptrDriver->setFieldName : #"<<fieldName<<"#");
537 ptrDriver->setFieldName(fieldName);
538 ptrField->addDriver(*ptrDriver);
539 // driver is duplicated : remove it
543 dtIt.dt = timeStepNumber;
544 dtIt.it = orderNumber;
546 (_fields [fieldName])[dtIt] = ptrField;
547 _meshName[ptrField ] = meshName;
552 delete[] componentName ;
557 // read profil count and their names
558 // int support_count_= 0 ; !! UNUSED VARIABLE !!
559 // il faut lire les champs pour avoir les profils stockes !!!
560 // il faudrait implémenter la lecture des profils dans med !!!
566 // This method ask the drivers of all MESH/FIELD objects created from this MED driver
567 // to read themselves
568 void MED_MED_RDONLY_DRIVER::read( void )
569 throw (MEDEXCEPTION) // from objects method read !
571 const char * LOC = "MED_MED_DRIVER::read() : ";
575 const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes);
576 map<MESH_NAME_,MESH*>::const_iterator currentMesh;
578 const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
579 map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
581 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ )
582 (*currentMesh).second->read(*this);
583 //(*currentMesh).second->read(); // default reader, from readFileStruct
586 _ptrMed->updateSupport() ;
588 for ( currentField =_meshName.begin(); currentField != _meshName.end(); currentField++ )
589 (*currentField).first->read(*this);
590 //(*currentField).first->read(); // default reader, from readFileStruct
595 void MED_MED_RDONLY_DRIVER::write(void) const
598 throw MEDEXCEPTION("MED_MED_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");
601 void MED_MED_RDONLY_DRIVER::writeFrom(void) const
604 throw MEDEXCEPTION("MED_MED_RDONLY_DRIVER::writeFrom : Can't write with a RDONLY driver !");
607 // ------------- Write Only Part --------------
609 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER():MED_MED_DRIVER()
613 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER(const string & fileName, MED * const ptrMed):
614 MED_MED_DRIVER(fileName,ptrMed)
617 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER(const MED_MED_WRONLY_DRIVER & driver):
618 MED_MED_DRIVER(driver)
621 MED_MED_WRONLY_DRIVER::~MED_MED_WRONLY_DRIVER()
623 MESSAGE("MED_MED_WRONLY_DRIVER::~MED_MED_WRONLY_DRIVER() has been destroyed");
626 GENDRIVER * MED_MED_WRONLY_DRIVER::copy(void) const
628 return new MED_MED_WRONLY_DRIVER(*this) ;
631 void MED_MED_WRONLY_DRIVER::read(void)
634 throw MEDEXCEPTION("MED_MED_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
637 void MED_MED_WRONLY_DRIVER::readFileStruct(void)
640 throw MEDEXCEPTION("MED_MED_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
643 // This method ask the drivers of all MESH/FIELD objects created from this MED driver
644 // to write themselves
645 void MED_MED_WRONLY_DRIVER::writeFrom( void) const
646 throw (MEDEXCEPTION) //from object method write !
648 const char * LOC = "MED_MED_DRIVER::writeFrom() : ";
652 const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes);
653 map<MESH_NAME_,MESH*>::const_iterator currentMesh;
655 const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
656 map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
658 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
660 (*currentMesh).second->write(*this);
661 // On utilise pour les objects MESH ET FIELD le write(GENDRIVER *) et le == ds GENDRIVER avec eventuellement 1 id
663 catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) {
668 for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
670 (*currentField).first->write(*this);
672 catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) {
681 void MED_MED_WRONLY_DRIVER::write(void ) const
682 throw (MEDEXCEPTION) // from object method write !
684 const char * LOC = "MED_MED_DRIVER::write() : ";
689 // BCLE SUR LES OBJETS AVEC AJOUT DE DRIVER ET APPELS write
691 const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes);
692 map<MESH_NAME_,MESH*>::const_iterator currentMesh;
694 const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
695 map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
697 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
698 //current = (*currentMesh).second->addDriver(MED_DRIVER,_fileName);
699 current = (*currentMesh).second->addDriver(MED_DRIVER,_fileName,(*currentMesh).second->getName());
700 // put right _id in Mesh driver (same as this._id)
701 (*currentMesh).second->_drivers[current]->setId( getId() );
702 //(*currentMesh).second->write(current) ;
705 for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
706 //current = (*currentField).first->addDriver(MED_DRIVER,_fileName);
707 current = (*currentField).first->addDriver(MED_DRIVER,_fileName,(*currentField).first->getName());
708 // put right _id in Field driver (same as this._id)
709 (*currentField).first->_drivers[current]->setId( getId() );
710 //(*currentField).first->write(current) ;
713 // that's work, but it is more efficenty to write directly when we had driver, no ?
720 // ------------- Read Write Part --------------
722 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER()
725 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER(const string & fileName, MED * const ptrMed):
726 MED_MED_DRIVER(fileName,ptrMed)
729 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER(const MED_MED_RDWR_DRIVER & driver):
730 MED_MED_DRIVER(driver)
733 MED_MED_RDWR_DRIVER::~MED_MED_RDWR_DRIVER() {
734 MESSAGE("MED_MED_RDWR_DRIVER::~MED_MED_RDWR_DRIVER() has been destroyed");
737 GENDRIVER * MED_MED_RDWR_DRIVER::copy(void) const
739 return new MED_MED_RDWR_DRIVER(*this) ;
742 void MED_MED_RDWR_DRIVER::read(void)
743 throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::read()
745 BEGIN_OF("MED_MED_RDWR_DRIVER::read(void)");
746 MED_MED_RDONLY_DRIVER::read();
747 END_OF("MED_MED_RDWR_DRIVER::read(void)");
750 void MED_MED_RDWR_DRIVER::readFileStruct(void)
751 throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::readFileStruct()
753 BEGIN_OF("MED_MED_RDWR_DRIVER::readFileStruct(void)");
754 MED_MED_RDONLY_DRIVER::readFileStruct();
755 END_OF("MED_MED_RDWR_DRIVER::readFileStruct(void)");
758 void MED_MED_RDWR_DRIVER::write(void) const
759 throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::write()
761 BEGIN_OF("MED_MED_RDWR_DRIVER::write(void) const");
762 MED_MED_WRONLY_DRIVER::write();
763 END_OF("MED_MED_RDWR_DRIVER::write(void) const");
766 void MED_MED_RDWR_DRIVER::writeFrom(void) const
767 throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::writeFrom();
769 BEGIN_OF("MED_MED_RDWR_DRIVER::writeFrom(void) const");
770 MED_MED_WRONLY_DRIVER::writeFrom();
771 END_OF("MED_MED_RDWR_DRIVER::writeFrom(void) const");