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;
18 using namespace MEDMEM;
20 MED_MED_DRIVER::MED_MED_DRIVER(): GENDRIVER(),
21 _ptrMed((MED * const)MED_NULL),_medIdt(MED_INVALID)
24 MED_MED_DRIVER::MED_MED_DRIVER(const string & fileName, MED * const ptrMed):
25 GENDRIVER(fileName,MED_EN::MED_RDWR), _ptrMed(ptrMed), _medIdt(MED_INVALID)
27 _ptrMed->addDriver(*this); // The specific MED driver id is set within the addDriver method.
30 MED_MED_DRIVER::MED_MED_DRIVER(const string & fileName,
32 MED_EN::med_mode_acces accessMode):
33 GENDRIVER(fileName,accessMode), _ptrMed(ptrMed), _medIdt(MED_INVALID)
36 //REM : As t'on besoin du champ _status : _medIdt <-> _status ? Oui
38 MED_MED_DRIVER::MED_MED_DRIVER(const MED_MED_DRIVER & driver):
40 _ptrMed(driver._ptrMed),
45 MED_MED_DRIVER::~MED_MED_DRIVER()
47 MESSAGE("MED_MED_DRIVER::~MED_MED_DRIVER() has been destroyed");
50 // GENDRIVER * MED_MED_DRIVER::copy(void) const
52 // return new MED_MED_DRIVER(*this) ;
54 void MED_MED_DRIVER::read()
57 void MED_MED_DRIVER::readFileStruct()
60 void MED_MED_DRIVER::write() const
63 GENDRIVER * MED_MED_DRIVER::copy(void) const
65 return new MED_MED_DRIVER(*this) ;
67 void MED_MED_DRIVER::writeFrom() const
73 void MED_MED_DRIVER::open()
77 const char * LOC ="MED_MED_DRIVER::open() : ";
80 // REFLECHIR SUR CE TEST PAR RAPPORT A L'OUVERTURE/FERMETURE
81 // if ( _medIdt != MED_INVALID )
82 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
83 // << "_medIdt is already in use, please close the file |"
84 // << _fileName << "| before calling open()"
88 // if ( _status != MED_CLOSED )
89 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
90 // << "_status is closed, please close the file |"
91 // << _fileName << "| before calling open()"
95 if ( _fileName == "" )
96 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
97 << "_fileName is |\"\"|, please set a correct fileName before calling open()"
101 MESSAGE(LOC<<"_fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode);
102 _medIdt = MEDouvrir( (const_cast <char *> (_fileName.c_str())), (MED_FR::med_mode_acces) _accessMode);
103 MESSAGE(LOC<<" _medIdt = "<<_medIdt);
108 _status = MED_CLOSED;
109 _medIdt = MED_INVALID;
110 throw MED_EXCEPTION (LOCALIZED( STRING(LOC)
111 << "Can't open |" << _fileName
112 << "|, _medIdt : " << _medIdt
121 void MED_MED_DRIVER::close()
123 MED_FR::med_int err = 0;
124 const char * LOC = "MED_MED_DRIVER::close() : ";
127 // if ( _status == MED_CLOSED)
128 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << ": the file |"
129 // << _fileName << "| is already closed"
133 // if ( _medIdt == MED_INVALID )
134 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "_medIdt invalid, but the file |"
135 // << _fileName << "| seems to be openned !"
139 if ( _medIdt != MED_INVALID )
140 err=MEDfermer(_medIdt);
142 // if (err != MED_VALID)
143 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "the file |"
144 // << _fileName << "| couldn't be closed"
148 _status = MED_CLOSED;
149 _medIdt = MED_INVALID;
155 // ------------- Read Only Part --------------
157 MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER():MED_MED_DRIVER()
161 MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const string & fileName, MED * const ptrMed):
162 MED_MED_DRIVER(fileName,ptrMed,MED_EN::MED_RDONLY)
164 MESSAGE("MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const string & fileName, MED * const ptrMed) Constructeur read only");
167 MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const MED_MED_RDONLY_DRIVER & driver):
168 MED_MED_DRIVER(driver)
172 MED_MED_RDONLY_DRIVER::~MED_MED_RDONLY_DRIVER()
174 MESSAGE("MED_MED_RDONLY_DRIVER::~MED_MED_RDONLY_DRIVER() has been destroyed");
177 GENDRIVER * MED_MED_RDONLY_DRIVER::copy(void) const
179 return new MED_MED_RDONLY_DRIVER(*this) ;
182 void MED_MED_RDONLY_DRIVER::readFileStruct( void )
185 const char * LOC = "MED_MED_DRIVER::readFileStruct() : ";
190 if ( _medIdt == MED_INVALID )
191 throw MED_EXCEPTION ( LOCALIZED( STRING(LOC)
192 << "_medIdt is invalid, please open the file |"
193 << _fileName << "| before calling readFileStruct()"
196 // Read number of meshes and their associated name
199 char meshName[MED_TAILLE_NOM+1]="";
200 char meshDescription[MED_TAILLE_DESC+1]="";
202 MED_FR::med_maillage meshType;
205 // MED_MESH_RDWR_DRIVER * ptrDriver; !! UNUSED VARIABLE !!
207 numberOfMeshes = MEDnMaa(_medIdt) ;
208 if ( numberOfMeshes <= 0 )
209 MESSAGE(LOC << "Be careful there is no mesh in file |"<<_fileName<<"| !");
211 MESH_ENTITIES::const_iterator currentEntity;
212 for (i=1;i<=numberOfMeshes;i++)
214 //get infoamation on the i^th mesh
216 err = MEDmaaInfo(_medIdt, i ,meshName, &meshDim, &meshType,
219 if (err != MED_VALID)
220 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << ": can't get information about the mesh n°" << i << " of the file |" << _fileName << "| !"));
224 case MED_FR::MED_STRUCTURE:
225 MESSAGE(LOC<<": Mesh n°"<< i <<" nammed "<< meshName << " with the description " << meshDescription << " is structured");
227 MED_FR::med_type_grille type;
229 err = MEDnatureGrilleLire(_medIdt, meshName, &type);
231 if (err != MED_VALID)
232 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << ": can't get the nature of the grid which is the mesh n°" << i << " of the file |" << _fileName << "| !"));
234 ptrMesh = new GRID((MED_EN::med_type_grille) type);
236 case MED_FR::MED_NON_STRUCTURE:
237 MESSAGE(LOC<<": Mesh n°"<< i <<" nammed "<< meshName << " with the description " << meshDescription << " is not structured");
239 ptrMesh = new MESH();
242 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mesh type !"));
245 // // find out if the mesh is a Grid
247 bool isAGrid = ptrMesh->getIsAGrid();
249 // MED_FR::med_grid_type type;
251 // err = MEDgridInfo (_medIdt, i, &isAGrid, &type);
252 // if (err != MED_VALID)
253 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "error in MEDgridInfo()") );
255 // err = MEDmaaInfo(_medIdt, i ,meshName, &meshDim) ;
256 // if (err != MED_VALID)
257 // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << ": can't get information about the mesh n°"
258 // << i <<" of the file |" << _fileName << "| !"
261 // MESSAGE(LOC<<": Mesh n°"<<i<<" nammed "<<meshName);
264 // ptrMesh = new GRID((MED_EN::med_grid_type) type);
266 // ptrMesh = new MESH();
268 //MED_MESH_RDWR_DRIVER * _ptrDriver = new MED_MESH_RDWR_DRIVER(_fileName, ptrMesh);
269 MED_EN::med_mode_acces myMode = getAccessMode();
270 MED_MESH_DRIVER * ptrDriver ;
272 // case MED_EN::MED_LECT: V2_1->V2_2
273 case MED_EN::MED_LECTURE:
274 ptrDriver = new MED_MESH_RDONLY_DRIVER(_fileName, ptrMesh);
276 // case MED_EN::MED_REMP: V2_1->V2_2
277 case MED_EN::MED_LECTURE_ECRITURE:
278 ptrDriver = new MED_MESH_RDWR_DRIVER(_fileName, ptrMesh);
280 // case MED_EN::MED_ECRI: // should never append !! V2_1->V2_2
281 case MED_EN::MED_LECTURE_AJOUT: // should never append !!
282 // ptrDriver = new MED_MESH_RDONLY_DRIVER(_fileName, ptrMesh);
283 ptrDriver = new MED_MESH_WRONLY_DRIVER(_fileName, ptrMesh);
285 case MED_EN::MED_CREATION: // V2_1->V2_2
286 ptrDriver = new MED_MESH_WRONLY_DRIVER(_fileName, ptrMesh);
289 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
291 ptrDriver->setId ( getId() );
292 ptrDriver->setMeshName ( meshName );
293 ptrMesh->addDriver(*ptrDriver);
297 _ptrMed->_meshes[meshName] = (MESH *) ptrMesh;
299 _ptrMed->_meshes[meshName] = ptrMesh;
301 _ptrMed->_meshes[meshName] = ptrMesh;
303 ptrMesh->setName(meshName);
305 ptrMesh->setDescription(meshDescription);
309 MESSAGE(LOC<<"is" << (isAGrid ? "" : " NOT") << " a GRID and its name is "<<ptrMesh->getName());
311 // we create all global support (for each entity type :
313 for (currentEntity=meshEntities.begin();currentEntity != meshEntities.end(); currentEntity++) {
314 string supportName="SupportOnAll_" ;
315 supportName+=entNames[(MED_FR::med_entite_maillage)(*currentEntity).first] ;
316 //(_ptrMed->_support)[meshName][(MED_FR::med_entite_maillage)(*currentEntity).first]=new SUPPORT(ptrMesh,supportName,(MED_EN::medEntityMesh) (*currentEntity).first) ;
317 SUPPORT* mySupport = new SUPPORT() ;
318 mySupport->setName(supportName);
319 mySupport->setMesh(ptrMesh);
320 mySupport->setEntity((MED_EN::medEntityMesh) (*currentEntity).first);
321 mySupport->setAll(true);
322 (_ptrMed->_support)[meshName][(MED_FR::med_entite_maillage)(*currentEntity).first] = mySupport ;
323 MESSAGE(LOC<< "The support " << supportName.c_str() << " on entity " << (*currentEntity).first << " is built");
326 MESSAGE(LOC <<"The mesh " <<ptrMesh->getName() << " has " << index << " support(s)");
329 map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::const_iterator const_itSupportOnMesh ;
333 vector<SUPPORT *> vectSupp;
334 for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
335 const_itSupportOnMesh++ )
337 map<MED_FR::med_entite_maillage,SUPPORT *>::const_iterator const_itSupport ;
338 for (const_itSupport=(*const_itSupportOnMesh).second.begin();
339 const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++) index++;
342 MESSAGE(LOC << "In this MED object there is(are) " << index << " support(s):");
344 vectSupp.resize(index);
347 for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
348 const_itSupportOnMesh++ )
350 map<MED_FR::med_entite_maillage,SUPPORT *>::const_iterator const_itSupport ;
351 for (const_itSupport=(*const_itSupportOnMesh).second.begin();
352 const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++)
354 vectSupp[index] = (*const_itSupport).second;
355 SCRUTE(vectSupp[index]);
356 MESSAGE(LOC << "Support number " << index << " is "<< *vectSupp[index]);
364 // Read number of fields, their associated name and their list of (timeStepNumber,iterationNumber)
366 int numberOfFields = 0; //MED_INVALID
367 // char fieldName[MED_TAILLE_NOM+1] = "";
368 char fieldName[MED_TAILLE_NOM+1] ;
369 int numberOfComponents = 0;
370 char * componentName = (char *) MED_NULL;
371 char * unitName = (char *) MED_NULL;
372 // char meshName[MED_TAILLE_NOM+1] = "";
373 char meshName[MED_TAILLE_NOM+1] ;
374 MED_FR::med_type_champ type;
375 MESH * ptrMesh = (MESH *) MED_NULL;
376 FIELD_ * ptrField = (FIELD_ *) MED_NULL;
377 //MED_FIELD_RDWR_DRIVER * ptrDriver = (MED_FIELD_RDWR_DRIVER * ) MED_NULL;
378 GENDRIVER * ptrDriver = (GENDRIVER * ) MED_NULL;
379 SUPPORT * ptrSupport = (SUPPORT * ) MED_NULL;
380 MESH_ENTITIES::const_iterator currentEntity;
381 list<MED_FR::med_geometrie_element>::const_iterator currentGeometry;
382 int NbOfGaussPts = 0;
383 int numberOfTimeSteps = -1;
384 int timeStepNumber = -1;
385 // char timeStepUnit[MED_TAILLE_PNOM]= "";
386 char timeStepUnit[MED_TAILLE_PNOM+1] ;
387 double timeStep = 0.0;
388 int orderNumber = -1; //???init?????
389 int numberOfRefMesh = 0;
390 MED_FR::med_booleen meshLink;
391 map<MESH_NAME_,MESH*> & _meshes = _ptrMed->_meshes;
392 map<FIELD_NAME_,MAP_DT_IT_> & _fields = _ptrMed->_fields;
393 map<FIELD_ *, MESH_NAME_> & _meshName = _ptrMed->_meshName;
394 map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> > & _support = _ptrMed->_support;
396 numberOfFields = MEDnChamp(_medIdt,0) ;
397 if ( numberOfFields <= 0 )
398 MESSAGE(LOC << "Be careful there is no field in file |"<<
401 for (i=1;i<=numberOfFields;i++)
403 numberOfComponents = MEDnChamp(_medIdt,i) ;
405 if ( numberOfComponents <= 0 )
406 if (err != MED_VALID)
407 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Be careful there is no compound for field n°" << i << "in file |"<<_fileName<<"| !"));
409 componentName = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;
410 unitName = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;
412 err = MEDchampInfo(_medIdt, i, fieldName, &type, componentName,
413 unitName, numberOfComponents) ;
415 if (err != MED_VALID)
416 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << ": can't get information about the field n°" << i <<" of the file |" << _fileName << "| !"));
418 MESSAGE(LOC << "Field n°"<<i<<" nammed "<< fieldName
419 << " ,component(s) : " << componentName
420 <<" ,unit(s) : " << unitName);
422 // Loop on all (entity type,geometry type) until you find an existing
423 // one then get the (n°dt,n°it) pairs list for the current
424 // (field,entity type,geometry type) We suppose there is the same list
425 // whatever the existing (entity type,geometry type) pair
429 for (currentEntity=meshEntities.begin();currentEntity != meshEntities.end(); currentEntity++)
431 // numberOfTimeSteps MUST be given by MEDchampInfo !!!!!
432 for (currentGeometry = (*currentEntity).second.begin();
433 currentGeometry != (*currentEntity).second.end();
436 MESSAGE("Field information with Entity,Geom = "<<
437 (*currentEntity).first<<","<<(*currentGeometry));
440 MEDnPasdetemps(_medIdt, fieldName,
441 (MED_FR::med_entite_maillage)(*currentEntity).first,
442 (MED_FR::med_geometrie_element) (*currentGeometry) );
444 MESSAGE("Field information 2 : NumberOfTimeStep :"<<
447 if ( numberOfTimeSteps > MED_VALID )
449 // There are value for some med_geometrie_element of this
450 // med_entite_maillage.
452 if (numberOfTimeSteps>0) // we have at least one
454 for (currentGeometry = (*currentEntity).second.begin();
455 currentGeometry != (*currentEntity).second.end();
458 MESSAGE("Field information 3 : Geom : "<<(*currentGeometry));
460 for (j=1;j <= numberOfTimeSteps; j++)
462 MESSAGE("Field information 4 : time step j = "<<j);
464 // err = MEDpasdetempsInfo( _medIdt, fieldName,
465 // (MED_FR::med_entite_maillage) (*currentEntity).first,
466 // (*currentGeometry),j, meshName,
467 // &NbOfGaussPts, &timeStepNumber,
468 // timeStepUnit, &timeStep, &orderNumber);
470 err = MEDpasdetempsInfo(_medIdt, fieldName,
471 (MED_FR::med_entite_maillage)
472 (*currentEntity).first,
473 (MED_FR::med_geometrie_element)
474 (*currentGeometry),j,
475 &NbOfGaussPts, &timeStepNumber,
476 &orderNumber, timeStepUnit,
477 &timeStep, meshName, &meshLink,
480 if (err == MED_VALID)
481 { // we have found for (*currentEntity).first and
482 // (*currentGeometry)
483 MESSAGE("Field information 5 ;: NumberOfGaussPoint : " << NbOfGaussPts << ", timeStepNumber : " << timeStepNumber << ", orderNumber : " << orderNumber);
484 // CORRECT a bug in MEDpasdetempsInfo :
485 // we get a value n'importe quoi in NbOfGaussPts !!!!
487 if (timeStepNumber<0) timeStepNumber=-1 ;
488 if ((numberOfRefMesh != 1) ||
489 (meshLink != MED_FR::MED_VRAI) ||
494 meshLink != MED_FR::MED_VRAI;
495 MESSAGE("This field is Med Memory compliant because NumberOfGaussPoint : " << NbOfGaussPts << ", or numberOfRefMesh : " << numberOfRefMesh << ", or meshLink : " << meshLink);
498 // ATTENTION TRAITER L'EXCEPTION CI DESSUS !!!!!!!!
500 // Il faudra traiter le cas d'un champ qui utilise
501 // +sieurs (entity,geom) voir le travail de patrick
502 // Il faudra traiter le cas des profils...
503 // ptrField = new FIELD();
504 // _ptrDriver = new MED_FIELD_RDWR_DRIVER(_fileName,
506 // ptrField->addDriver(_ptrDriver);
507 // _fields[fieldName]=ptrField;
509 // Verify meshName is already known
511 map<MESH_NAME_,MESH*>::iterator _meshesIt =
512 _meshes.find(meshName);
513 if ( _meshesIt == _meshes.end() ) {
514 MESSAGE(LOC << "There is no mesh |" << meshName <<
515 "| in the file |" << _fileName <<
516 "|, but |" << meshName <<
517 "| is referenced by field |" <<
518 fieldName <<"|, entity : |" <<
519 entNames [ (MED_FR::med_entite_maillage)
520 (*currentEntity).first] <<
521 "|, geometric element of type |" <<
522 geoNames [ (MED_FR::med_geometrie_element)
523 (*currentGeometry)] <<"|");
525 // POURQUOI SI JE NE MET PAS DE BLOCK J'AI UN PARSE
526 // ERROR : PG : c'est la macro MESSAGE qui fait ca !
528 ptrMesh = _meshes[meshName];
530 ptrSupport = _support[meshName][(MED_FR::med_entite_maillage) (*currentEntity).first];
531 if (NbOfGaussPts != 1)
532 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Number of Gauss Point must be equal to 1 for instance")) ;
534 // init to null to prevent some error if not
535 // correctly allocated !
537 ptrField = (FIELD_*)NULL ;
538 ptrDriver = (GENDRIVER*)NULL ;
541 case MED_FR::MED_INT64 :
542 if ( sizeof(MED_FR::med_int) != 8 )
543 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) <<" The Field type of |" << fieldName <<"|, entity : |" << entNames [(MED_FR::med_entite_maillage) (*currentEntity).first] <<"|, geometric element of type |" << geoNames [(MED_FR::med_geometrie_element) (*currentGeometry) ] << "| is MED_INT64 but size of med_int is not equal to 8 bytes !"));
545 case MED_FR::MED_INT32 : {
546 // throw MED_EXCEPTION(LOCALIZED(STRING(LOC) <<
547 // "NOT IMPLEMENTED : BUG IN STL !")
549 // ptrField = new FIELD<MED_FR::med_int> (ptrSupport,numberOfComponents);
550 // Les valeurs du champ ne doivent pas être lue
553 ptrField = new FIELD<MED_FR::med_int> ( );
554 // Les valeurs du champ ne doivent pas être lue
556 ((FIELD<MED_FR::med_int>*)
557 ptrField)->setSupport(ptrSupport);
558 ((FIELD<MED_FR::med_int>*)
559 ptrField)->setNumberOfComponents(numberOfComponents);
560 ((FIELD<MED_FR::med_int>*)
561 ptrField)->setName(fieldName) ;
562 //provisoire, pour debug
563 MESSAGE("#### SET NAME in FIELD : "<<fieldName);
565 MED_EN::med_mode_acces myMode = getAccessMode();
567 // case MED_EN::MED_LECT: V2_1->V2_2
568 case MED_EN::MED_LECTURE:
570 MED_FIELD_RDONLY_DRIVER<MED_FR::med_int>
571 (_fileName, (FIELD<MED_FR::med_int> *)
574 // case MED_EN::MED_REMP: V2_1->V2_2
575 case MED_EN::MED_LECTURE_ECRITURE:
577 MED_FIELD_RDWR_DRIVER<MED_FR::med_int>
578 (_fileName, (FIELD<MED_FR::med_int> *)
581 // case MED_EN::MED_ECRI:
582 // should never append !! V2_1->V2_2
583 case MED_EN::MED_LECTURE_AJOUT:
584 // should never append !!
586 // MED_FIELD_RDONLY_DRIVER<MED_FR::med_int>
587 // (_fileName, (FIELD<MED_FR::med_int> *)
590 MED_FIELD_WRONLY_DRIVER<MED_FR::med_int>
591 (_fileName, (FIELD<MED_FR::med_int> *)
594 case MED_EN::MED_CREATION: // V2_1->V2_2
596 MED_FIELD_WRONLY_DRIVER<MED_FR::med_int>
597 (_fileName, (FIELD<MED_FR::med_int> *)
601 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
605 case MED_EN::MED_REEL64 : {
606 // ptrField = new FIELD<MED_FR::med_float>
607 // (ptrSupport,numberOfComponents );
608 // Les valeurs du champ ne doivent pas être lue
610 ptrField = new FIELD<MED_FR::med_float> ( );
611 // Les valeurs du champ ne doivent pas être lue
613 ((FIELD<MED_FR::med_float>*)
614 ptrField)->setSupport(ptrSupport);
615 ((FIELD<MED_FR::med_float>*)
616 ptrField)->setNumberOfComponents(numberOfComponents);
617 ((FIELD<MED_FR::med_float>*)
618 ptrField)->setName(fieldName) ;
619 //provisoire, pour debug
620 MESSAGE("#### SET NAME in FIELD : "<<fieldName);
622 MED_EN::med_mode_acces myMode = getAccessMode();
624 // case MED_EN::MED_LECT: V2_1->V2_2
625 case MED_EN::MED_LECTURE:
627 MED_FIELD_RDONLY_DRIVER<MED_FR::med_float>
628 (_fileName, (FIELD<MED_FR::med_float> *)
631 // case MED_EN::MED_REMP: V2_1->V2_2
632 case MED_EN::MED_LECTURE_ECRITURE:
634 MED_FIELD_RDWR_DRIVER<MED_FR::med_float>
635 (_fileName, (FIELD<MED_FR::med_float> *)
638 // case MED_EN::MED_ECRI:
639 // should never append !! V2_1->V2_2
640 case MED_EN::MED_LECTURE_AJOUT:
641 // should never append !!
643 // MED_FIELD_RDONLY_DRIVER<MED_FR::med_float>
644 // (_fileName, (FIELD<MED_FR::med_float> *)
647 MED_FIELD_WRONLY_DRIVER<MED_FR::med_float>
648 (_fileName, (FIELD<MED_FR::med_float> *)
651 case MED_EN::MED_CREATION:
652 // should never append !!
654 MED_FIELD_WRONLY_DRIVER<MED_FR::med_float>
655 (_fileName, (FIELD<MED_FR::med_float> *)
659 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
664 if ( numberOfTimeSteps > 1)
665 throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << " The Field type of |" << fieldName <<"|, entity : |" << entNames [(MED_FR::med_entite_maillage) (*currentEntity).first] <<"|, geometric element of type |" << geoNames [(MED_FR::med_geometrie_element) (*currentGeometry)] <<"| is neither MED_INT, MED_INT32, MED_INT64 nor MED_REEL64 !"));
669 ptrField->setValueType((MED_EN::med_type_champ)
671 // need to write field !
673 MESSAGE("timeStepNumber :"<<timeStepNumber<<
674 ",orderNumber :"<<orderNumber);
675 ptrField->setIterationNumber ( timeStepNumber);
676 // A ajouter dans la classe FIELD
677 ptrField->setOrderNumber ( orderNumber);
678 ptrField->setTime ( timeStep);
680 // Create a driver for this (field n°dt,n°it)
681 ptrDriver->setId ( getId() );
682 MESSAGE("###### ptrDriver->setFieldName : #"<<
684 ptrDriver->setFieldName(fieldName);
685 ptrField->addDriver(*ptrDriver);
686 // driver is duplicated : remove it
690 dtIt.dt = timeStepNumber;
691 dtIt.it = orderNumber;
693 (_fields [fieldName])[dtIt] = ptrField;
694 _meshName[ptrField ] = meshName;
699 delete[] componentName ;
704 // read profil count and their names
705 // int support_count_= 0 ; !! UNUSED VARIABLE !!
706 // il faut lire les champs pour avoir les profils stockes !!!
707 // il faudrait implémenter la lecture des profils dans med !!!
713 // This method ask the drivers of all MESH/FIELD objects created from this MED driver
714 // to read themselves
715 void MED_MED_RDONLY_DRIVER::read( void )
716 throw (MEDEXCEPTION) // from objects method read !
718 const char * LOC = "MED_MED_DRIVER::read() : ";
722 const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes);
723 map<MESH_NAME_,MESH*>::const_iterator currentMesh;
725 const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
726 map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
728 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ )
729 (*currentMesh).second->read(*this);
730 //(*currentMesh).second->read(); // default reader, from readFileStruct
733 _ptrMed->updateSupport() ;
735 for ( currentField =_meshName.begin(); currentField != _meshName.end(); currentField++ )
736 (*currentField).first->read(*this);
737 //(*currentField).first->read(); // default reader, from readFileStruct
742 void MED_MED_RDONLY_DRIVER::write(void) const
745 throw MEDEXCEPTION("MED_MED_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");
748 void MED_MED_RDONLY_DRIVER::writeFrom(void) const
751 throw MEDEXCEPTION("MED_MED_RDONLY_DRIVER::writeFrom : Can't write with a RDONLY driver !");
754 // ------------- Write Only Part --------------
756 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER():MED_MED_DRIVER()
760 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER(const string & fileName, MED * const ptrMed):
761 MED_MED_DRIVER(fileName,ptrMed)
764 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER(const MED_MED_WRONLY_DRIVER & driver):
765 MED_MED_DRIVER(driver)
768 MED_MED_WRONLY_DRIVER::~MED_MED_WRONLY_DRIVER()
770 MESSAGE("MED_MED_WRONLY_DRIVER::~MED_MED_WRONLY_DRIVER() has been destroyed");
773 GENDRIVER * MED_MED_WRONLY_DRIVER::copy(void) const
775 return new MED_MED_WRONLY_DRIVER(*this) ;
778 void MED_MED_WRONLY_DRIVER::read(void)
781 throw MEDEXCEPTION("MED_MED_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
784 void MED_MED_WRONLY_DRIVER::readFileStruct(void)
787 throw MEDEXCEPTION("MED_MED_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
790 // This method ask the drivers of all MESH/FIELD objects created from this MED driver
791 // to write themselves
792 void MED_MED_WRONLY_DRIVER::writeFrom( void) const
793 throw (MEDEXCEPTION) //from object method write !
795 const char * LOC = "MED_MED_DRIVER::writeFrom() : ";
799 const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes);
800 map<MESH_NAME_,MESH*>::const_iterator currentMesh;
802 const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
803 map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
805 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
807 (*currentMesh).second->write(*this);
808 // On utilise pour les objects MESH ET FIELD le write(GENDRIVER *) et le == ds GENDRIVER avec eventuellement 1 id
810 catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) {
815 for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
817 (*currentField).first->write(*this);
819 catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) {
828 void MED_MED_WRONLY_DRIVER::write(void ) const
829 throw (MEDEXCEPTION) // from object method write !
831 const char * LOC = "MED_MED_DRIVER::write() : ";
836 // BCLE SUR LES OBJETS AVEC AJOUT DE DRIVER ET APPELS write
838 const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes);
839 map<MESH_NAME_,MESH*>::const_iterator currentMesh;
841 const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
842 map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
844 for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
845 //current = (*currentMesh).second->addDriver(MED_DRIVER,_fileName);
846 current = (*currentMesh).second->addDriver(MED_DRIVER,_fileName,(*currentMesh).second->getName());
847 // put right _id in Mesh driver (same as this._id)
848 (*currentMesh).second->_drivers[current]->setId( getId() );
849 //(*currentMesh).second->write(current) ;
852 for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
853 //current = (*currentField).first->addDriver(MED_DRIVER,_fileName);
854 current = (*currentField).first->addDriver(MED_DRIVER,_fileName,(*currentField).first->getName());
855 // put right _id in Field driver (same as this._id)
856 (*currentField).first->_drivers[current]->setId( getId() );
857 //(*currentField).first->write(current) ;
860 // that's work, but it is more efficenty to write directly when we had driver, no ?
867 // ------------- Read Write Part --------------
869 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER()
872 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER(const string & fileName, MED * const ptrMed):
873 MED_MED_DRIVER(fileName,ptrMed)
876 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER(const MED_MED_RDWR_DRIVER & driver):
877 MED_MED_DRIVER(driver)
880 MED_MED_RDWR_DRIVER::~MED_MED_RDWR_DRIVER() {
881 MESSAGE("MED_MED_RDWR_DRIVER::~MED_MED_RDWR_DRIVER() has been destroyed");
884 GENDRIVER * MED_MED_RDWR_DRIVER::copy(void) const
886 return new MED_MED_RDWR_DRIVER(*this) ;
889 void MED_MED_RDWR_DRIVER::read(void)
890 throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::read()
892 BEGIN_OF("MED_MED_RDWR_DRIVER::read(void)");
893 MED_MED_RDONLY_DRIVER::read();
894 END_OF("MED_MED_RDWR_DRIVER::read(void)");
897 void MED_MED_RDWR_DRIVER::readFileStruct(void)
898 throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::readFileStruct()
900 BEGIN_OF("MED_MED_RDWR_DRIVER::readFileStruct(void)");
901 MED_MED_RDONLY_DRIVER::readFileStruct();
902 END_OF("MED_MED_RDWR_DRIVER::readFileStruct(void)");
905 void MED_MED_RDWR_DRIVER::write(void) const
906 throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::write()
908 BEGIN_OF("MED_MED_RDWR_DRIVER::write(void) const");
909 MED_MED_WRONLY_DRIVER::write();
910 END_OF("MED_MED_RDWR_DRIVER::write(void) const");
913 void MED_MED_RDWR_DRIVER::writeFrom(void) const
914 throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::writeFrom();
916 BEGIN_OF("MED_MED_RDWR_DRIVER::writeFrom(void) const");
917 MED_MED_WRONLY_DRIVER::writeFrom();
918 END_OF("MED_MED_RDWR_DRIVER::writeFrom(void) const");