]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_MedMedDriver.cxx
Salome HOME
update from the MedMemory V1.0.1
[modules/med.git] / src / MEDMEM / MEDMEM_MedMedDriver.cxx
1 using namespace std;
2 # include <string>
3
4 # include "MEDMEM_MedMedDriver.hxx"
5
6 # include "MEDMEM_DriversDef.hxx"
7
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"
14
15 # include "MEDMEM_define.hxx"
16
17 using namespace MED_FR;
18
19 MED_MED_DRIVER::MED_MED_DRIVER(): GENDRIVER(), 
20                                   _ptrMed((MED * const)MED_NULL),_medIdt(MED_INVALID) 
21 {}
22
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)
25 {
26   _ptrMed->addDriver(*this); // The specific MED driver id is set within the addDriver method.
27 }
28
29 MED_MED_DRIVER::MED_MED_DRIVER(const string & fileName,
30                                MED * const ptrMed,
31                                MED_EN::med_mode_acces accessMode):
32   GENDRIVER(fileName,accessMode), _ptrMed(ptrMed), _medIdt(MED_INVALID)
33 {
34 }
35 //REM :  As t'on besoin du champ _status :  _medIdt <-> _status  ?  Oui
36
37 MED_MED_DRIVER::MED_MED_DRIVER(const MED_MED_DRIVER & driver):
38   GENDRIVER(driver),
39   _ptrMed(driver._ptrMed),
40   _medIdt(MED_INVALID)
41 {
42 }
43
44 MED_MED_DRIVER::~MED_MED_DRIVER()
45 {
46   MESSAGE("MED_MED_DRIVER::~MED_MED_DRIVER() has been destroyed");
47 }
48
49 //  GENDRIVER * MED_MED_DRIVER::copy(void) const
50 //  {
51 //    return new MED_MED_DRIVER(*this) ;
52 //  }
53 void MED_MED_DRIVER::read()
54 {
55 }
56 void MED_MED_DRIVER::readFileStruct()
57 {
58 }
59 void MED_MED_DRIVER::write() const
60 {
61 }
62 GENDRIVER * MED_MED_DRIVER::copy(void) const
63 {
64   return new MED_MED_DRIVER(*this) ;
65 }
66 void MED_MED_DRIVER::writeFrom() const
67 {
68 }
69
70
71
72 void MED_MED_DRIVER::open()
73   throw (MEDEXCEPTION)
74 {
75
76   const char * LOC ="MED_MED_DRIVER::open() : ";
77   BEGIN_OF(LOC);
78
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()"
84 //                                       )
85 //                            );   
86   
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()"
91 //                                       )
92 //                            );
93   
94   if ( _fileName == "" )
95     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
96                                      << "_fileName is |\"\"|, please set a correct fileName before calling open()"
97                                      )
98                           );
99   
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);
103   
104   if (_medIdt > 0) 
105     _status=MED_OPENED; 
106   else {
107     _status = MED_CLOSED;
108     _medIdt = MED_INVALID;
109     throw MED_EXCEPTION (LOCALIZED( STRING(LOC) 
110                                     << "Can't open |"  << _fileName 
111                                     << "|, _medIdt : " << _medIdt
112                                     )
113                          );
114   }
115
116   END_OF(LOC);
117 }
118
119
120 void MED_MED_DRIVER::close()
121 {
122   MED_FR::med_int err = 0;
123   const char * LOC = "MED_MED_DRIVER::close() : ";
124   
125   
126 //    if ( _status == MED_CLOSED)
127 //      throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << ": the file |" 
128 //                                       << _fileName << "| is already closed"
129 //                                       )
130 //                            );
131    
132 //    if ( _medIdt == MED_INVALID ) 
133 //      throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "_medIdt invalid, but the file |" 
134 //                                       << _fileName << "| seems to be openned !"
135 //                                       )
136 //                            );   
137
138   if ( _medIdt != MED_INVALID )
139     err=MEDfermer(_medIdt);
140   
141 //    if (err != MED_VALID) 
142 //      throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "the file |" 
143 //                                       << _fileName << "| couldn't be closed"
144 //                                       )
145 //                            );   
146   
147   _status = MED_CLOSED;
148   _medIdt = MED_INVALID;
149     
150   END_OF(LOC);
151 }
152
153
154 // ------------- Read Only Part --------------
155
156 MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER():MED_MED_DRIVER()
157 {
158 }
159
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)
162 {
163   MESSAGE("MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const string & fileName,  MED * const ptrMed) Constructeur read only");
164 }
165
166 MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const MED_MED_RDONLY_DRIVER & driver):
167   MED_MED_DRIVER(driver)
168 {
169 }
170
171 MED_MED_RDONLY_DRIVER::~MED_MED_RDONLY_DRIVER()
172 {
173   MESSAGE("MED_MED_RDONLY_DRIVER::~MED_MED_RDONLY_DRIVER() has been destroyed");
174
175
176 GENDRIVER * MED_MED_RDONLY_DRIVER::copy(void) const
177 {
178   return new MED_MED_RDONLY_DRIVER(*this) ;
179 }
180
181 void MED_MED_RDONLY_DRIVER::readFileStruct( void ) 
182   throw (MEDEXCEPTION)
183 {
184   const char * LOC = "MED_MED_DRIVER::readFileStruct() : ";
185   int          err,i,j;
186       
187   BEGIN_OF(LOC);
188
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()"
193                                      )
194                           );   
195   // Read number of meshes and their associated name
196   {
197     int          numberOfMeshes;
198     char         meshName[MED_TAILLE_NOM+1]="";
199     int          meshDim;
200     MESH *       ptrMesh;
201     //    MED_MESH_RDWR_DRIVER * ptrDriver; !! UNUSED VARIABLE !!
202     
203     numberOfMeshes = MEDnMaa(_medIdt) ;
204     if ( numberOfMeshes <= 0 ) 
205       MESSAGE(LOC << "Be careful there is no mesh in file |"<<_fileName<<"| !");
206
207     MESH_ENTITIES::const_iterator currentEntity; 
208     for (i=1;i<=numberOfMeshes;i++) {
209
210       // find out if the mesh is a Grid
211       
212       int isAGrid = false;
213       MED_FR::med_grid_type type;
214       
215       err = MEDgridInfo (_medIdt, i, &isAGrid, &type);
216       if (err != MED_VALID) 
217         throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "error in MEDgridInfo()") );
218
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 << "| !"
223                                          )
224                               );   
225       MESSAGE(LOC<<": Mesh n°"<<i<<" nammed "<<meshName);
226
227       if (isAGrid)
228         ptrMesh = new GRID((MED_EN::med_grid_type) type);
229       else
230         ptrMesh = new MESH();
231
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 ;
235       switch (myMode) {
236       case MED_EN::MED_LECT:
237         ptrDriver = new MED_MESH_RDONLY_DRIVER(_fileName, ptrMesh);
238         break ;
239       case MED_EN::MED_REMP:    
240         ptrDriver = new MED_MESH_RDWR_DRIVER(_fileName, ptrMesh);
241         break ;
242       case MED_EN::MED_ECRI: // should never append !!
243         ptrDriver = new MED_MESH_RDONLY_DRIVER(_fileName, ptrMesh);
244         break;
245       default:
246         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
247       }
248       ptrDriver->setId       ( getId() );
249       ptrDriver->setMeshName ( meshName );
250       ptrMesh->addDriver(*ptrDriver);
251       delete ptrDriver ;
252
253       if (isAGrid)
254         _ptrMed->_meshes[meshName] = (MESH *) ptrMesh;
255       else
256         _ptrMed->_meshes[meshName] = ptrMesh;
257
258       ptrMesh->setName(meshName);
259
260       SCRUTE(ptrMesh);
261
262       MESSAGE(LOC<<"is" << (isAGrid ? "" : " NOT") << " a GRID and its name is "<<ptrMesh->getName());
263
264       // we create all global support (for each entity type :
265       int index = 0;
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");
277         index++;
278       }
279       MESSAGE(LOC <<"The mesh " <<ptrMesh->getName() << " has " << index << " support(s)");
280     }
281
282     map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::const_iterator const_itSupportOnMesh ;
283
284     int index = 0;
285
286     vector<SUPPORT *> vectSupp;
287     for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
288          const_itSupportOnMesh++ )
289       {
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++;
293       }
294
295     MESSAGE(LOC << "In this MED object there is(are) " << index << " support(s):");
296
297     vectSupp.resize(index);
298
299     index = 0;
300     for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
301          const_itSupportOnMesh++ )
302       {
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++)
306           {
307             vectSupp[index] = (*const_itSupport).second;
308             SCRUTE(vectSupp[index]);
309             MESSAGE(LOC << "Support number " << index << " is "<< *vectSupp[index]);
310             index++;
311           }
312       }
313
314   }
315   
316   
317   // Read number of fields, their associated name and their list of (timeStepNumber,iterationNumber)
318   {
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;
346
347     
348     numberOfFields = MEDnChamp(_medIdt,0) ;
349     if ( numberOfFields <= 0 ) 
350       MESSAGE(LOC << "Be careful there is no field in file |"<<_fileName<<"| !");
351   
352     for (i=1;i<=numberOfFields;i++) {
353
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<<"| !"));
359       
360       componentName = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;
361       unitName      = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;   
362       
363       err = MEDchampInfo(_medIdt, i, fieldName, &type, componentName, 
364                          unitName, numberOfComponents) ;
365
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 << "| !")); 
370       
371       MESSAGE(LOC << "Field n°"<<i<<" nammed "<< fieldName 
372               << " ,component(s)  : " << componentName 
373               <<" ,unit(s) : "        << unitName);
374       
375
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  
379       // support map :
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.
390         }
391         if (numberOfTimeSteps>0) // we have at least one
392           
393           for (currentGeometry  = (*currentEntity).second.begin();currentGeometry != (*currentEntity).second.end(); currentGeometry++) {            
394             
395             MESSAGE("Field information 3 : Geom : "<<(*currentGeometry));
396             for (j=1;j <= numberOfTimeSteps; j++) {
397               
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,
404                                        &orderNumber);
405               if (err == MED_VALID) { // we have found for (*currentEntity).first and (*currentGeometry)
406                 
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 !!!!
410                 
411                 if (NbOfGaussPts>100)
412                   NbOfGaussPts=1 ;
413                 if (timeStepNumber<0)
414                   timeStepNumber=-1 ;
415                 
416                 
417                 // ATTENTION TRAITER L'EXCEPTION !!!!!!!!!!!!
418                 
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;
425                 
426                 // Verify meshName is already known
427                 
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)]     <<"|" 
436                           ); 
437                 }  // POURQUOI SI JE NE MET PAS DE BLOCK J'AI UN PARSE ERROR : PG : c'est la macro MESSAGE qui fait ca !
438                 else 
439                   ptrMesh = _meshes[meshName];
440                 
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")) ;
444                 
445                 // init to null to prevent some error if not correctly allocated !
446                 ptrField = (FIELD_*)NULL ;
447                 ptrDriver = (GENDRIVER*)NULL ;
448
449                 switch ( type) {
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 !" 
458                                                      ) 
459                                           );
460                   break;
461                 case MED_FR::MED_INT32 : {
462 //                throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) <<
463 //                                                 "NOT IMPLEMENTED : BUG IN STL !")
464 //                                      ) ;
465                   // ptrField       =  new FIELD<MED_FR::med_int>   ( ptrSupport,numberOfComponents );   // Les valeurs du champ ne doivent pas être lue pour l'instant
466
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);
472
473                   MED_EN::med_mode_acces myMode = getAccessMode();
474                   switch (myMode) {
475                   case MED_EN::MED_LECT:
476                     ptrDriver = new MED_FIELD_RDONLY_DRIVER<MED_FR::med_int>(_fileName, (FIELD<MED_FR::med_int> *)ptrField);
477                     break ;
478                   case MED_EN::MED_REMP:        
479                     ptrDriver = new MED_FIELD_RDWR_DRIVER<MED_FR::med_int>(_fileName, (FIELD<MED_FR::med_int> *)ptrField);
480                     break ;
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);
483                     break;
484                   default:
485                     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
486                   }
487                   break;
488                 }
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);
496
497                   MED_EN::med_mode_acces myMode = getAccessMode();
498                   switch (myMode) {
499                   case MED_EN::MED_LECT:
500                     ptrDriver = new MED_FIELD_RDONLY_DRIVER<MED_FR::med_float>(_fileName, (FIELD<MED_FR::med_float> *)ptrField);
501                     break ;
502                   case MED_EN::MED_REMP:        
503                     ptrDriver = new MED_FIELD_RDWR_DRIVER<MED_FR::med_float>(_fileName, (FIELD<MED_FR::med_float> *)ptrField);
504                     break ;
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);
507                     break;
508                   default:
509                     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
510                   }
511                   break;
512                 }
513                 default : {
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 !" 
522                                                      ) 
523                                           );
524                   break ;
525                 }
526                 }
527                 ptrField->setValueType((MED_EN::med_type_champ) type) ; // need to write field !
528                 
529                 MESSAGE("timeStepNumber :"<<timeStepNumber<<",orderNumber :"<<orderNumber);
530                 ptrField->setIterationNumber ( timeStepNumber);      // A ajouter dans la classe FIELD
531                 ptrField->setOrderNumber     ( orderNumber); 
532                 ptrField->setTime            ( timeStep); 
533                 
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
540                 delete ptrDriver;
541
542                 DT_IT_ dtIt;
543                 dtIt.dt  = timeStepNumber;
544                 dtIt.it  = orderNumber;
545                 
546                 (_fields  [fieldName])[dtIt] = ptrField;
547                 _meshName[ptrField ]       = meshName;
548               }
549             }
550           }
551       }
552       delete[] componentName ;
553       delete[] unitName ;
554     }
555   }
556   
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 !!!
561   
562   END_OF(LOC);
563   
564 }
565
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 !
570 {
571   const char * LOC = "MED_MED_DRIVER::read() : ";
572  
573   BEGIN_OF(LOC);
574
575   const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes); 
576   map<MESH_NAME_,MESH*>::const_iterator  currentMesh;
577
578   const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
579   map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
580   
581   for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) 
582     (*currentMesh).second->read(*this); 
583   //(*currentMesh).second->read(); // default reader, from readFileStruct
584     
585   // PROVISOIRE
586   _ptrMed->updateSupport() ;
587
588   for ( currentField =_meshName.begin(); currentField != _meshName.end(); currentField++ )
589     (*currentField).first->read(*this);
590   //(*currentField).first->read(); // default reader, from readFileStruct
591
592   END_OF(LOC);
593 }
594
595 void MED_MED_RDONLY_DRIVER::write(void) const
596   throw (MEDEXCEPTION)
597 {
598   throw MEDEXCEPTION("MED_MED_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");
599 }
600
601 void MED_MED_RDONLY_DRIVER::writeFrom(void) const
602   throw (MEDEXCEPTION)
603 {
604   throw MEDEXCEPTION("MED_MED_RDONLY_DRIVER::writeFrom : Can't write with a RDONLY driver !");
605 }
606
607 // ------------- Write Only Part --------------
608
609 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER():MED_MED_DRIVER()
610 {
611 }
612
613 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER(const string & fileName,  MED * const ptrMed):
614   MED_MED_DRIVER(fileName,ptrMed)
615 {}
616
617 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER(const MED_MED_WRONLY_DRIVER & driver):
618   MED_MED_DRIVER(driver)
619 {}
620
621 MED_MED_WRONLY_DRIVER::~MED_MED_WRONLY_DRIVER()
622 {
623   MESSAGE("MED_MED_WRONLY_DRIVER::~MED_MED_WRONLY_DRIVER() has been destroyed");
624
625
626 GENDRIVER * MED_MED_WRONLY_DRIVER::copy(void) const
627 {
628   return new MED_MED_WRONLY_DRIVER(*this) ;
629 }
630
631 void MED_MED_WRONLY_DRIVER::read(void)
632   throw (MEDEXCEPTION)
633 {
634   throw MEDEXCEPTION("MED_MED_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
635 }
636
637 void MED_MED_WRONLY_DRIVER::readFileStruct(void)
638   throw (MEDEXCEPTION)
639 {
640   throw MEDEXCEPTION("MED_MED_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
641 }
642
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 !
647 {
648   const char * LOC = "MED_MED_DRIVER::writeFrom() : ";
649
650   BEGIN_OF(LOC);
651
652   const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes); 
653   map<MESH_NAME_,MESH*>::const_iterator  currentMesh;
654
655   const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
656   map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
657   
658   for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
659     try {
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 
662     }
663     catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) {
664       continue;
665     }
666   }
667
668   for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
669     try {
670       (*currentField).first->write(*this);
671     }
672     catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) {
673       continue;
674     }
675   }
676
677   END_OF(LOC);
678
679 }
680
681 void MED_MED_WRONLY_DRIVER::write(void ) const
682   throw (MEDEXCEPTION) // from object method write !
683 {
684   const char * LOC = "MED_MED_DRIVER::write() : ";
685   int current;
686
687   BEGIN_OF(LOC);
688
689   // BCLE SUR LES OBJETS AVEC AJOUT DE DRIVER ET APPELS write
690
691   const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes); 
692   map<MESH_NAME_,MESH*>::const_iterator  currentMesh;
693
694   const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
695   map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
696   
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) ;
703   }
704
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) ;
711   }
712
713   // that's work, but it is more efficenty to write directly when we had driver, no ?
714   writeFrom();
715   
716   END_OF(LOC);
717
718 }
719
720 // ------------- Read Write Part --------------
721
722 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER()
723 {}
724
725 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER(const string & fileName,  MED * const ptrMed):
726   MED_MED_DRIVER(fileName,ptrMed)
727 {}
728
729 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER(const MED_MED_RDWR_DRIVER & driver):
730   MED_MED_DRIVER(driver)
731 {}
732
733 MED_MED_RDWR_DRIVER::~MED_MED_RDWR_DRIVER() { 
734   MESSAGE("MED_MED_RDWR_DRIVER::~MED_MED_RDWR_DRIVER() has been destroyed");
735 }
736
737 GENDRIVER * MED_MED_RDWR_DRIVER::copy(void) const
738 {
739   return new MED_MED_RDWR_DRIVER(*this) ;
740 }
741
742 void MED_MED_RDWR_DRIVER::read(void)
743   throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::read()
744 {
745   BEGIN_OF("MED_MED_RDWR_DRIVER::read(void)");
746   MED_MED_RDONLY_DRIVER::read();
747   END_OF("MED_MED_RDWR_DRIVER::read(void)");
748 }
749
750 void MED_MED_RDWR_DRIVER::readFileStruct(void)
751   throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::readFileStruct()
752 {
753   BEGIN_OF("MED_MED_RDWR_DRIVER::readFileStruct(void)");
754   MED_MED_RDONLY_DRIVER::readFileStruct();
755   END_OF("MED_MED_RDWR_DRIVER::readFileStruct(void)");
756 }
757
758 void MED_MED_RDWR_DRIVER::write(void) const
759   throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::write()
760 {
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");
764 }
765
766 void MED_MED_RDWR_DRIVER::writeFrom(void) const
767   throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::writeFrom();
768 {
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");
772 }