Salome HOME
f6491447937044b057ab3ee8e2eac583460fa579
[modules/med.git] / src / MEDMEM / MEDMEM_MedMedDriver.cxx
1 # include <string>
2
3 # include "MEDMEM_MedMedDriver.hxx"
4 # include "MEDMEM_MedMeshDriver.hxx"
5 # include "MEDMEM_DriversDef.hxx"
6
7 # include "MEDMEM_Mesh.hxx"
8 # include "MEDMEM_Grid.hxx"
9 # include "MEDMEM_Field.hxx"
10 // EN ATTENDANT L'utilisation de MedFieldDriver.hxx ds Field.hxx
11 # include "MEDMEM_MedFieldDriver.hxx"
12 # include "MEDMEM_Med.hxx"
13
14 # include "MEDMEM_define.hxx"
15
16 using namespace std;
17 using namespace MED_EN;
18 using namespace MEDMEM;
19
20 MED_MED_DRIVER::MED_MED_DRIVER(): GENDRIVER(), 
21                                   _ptrMed((MED * const)MED_NULL),_medIdt(MED_INVALID) 
22 {}
23
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)
26 {
27   //_ptrMed->addDriver(*this); // The specific MED driver id is set within the addDriver method.
28 }
29
30 MED_MED_DRIVER::MED_MED_DRIVER(const string & fileName,
31                                MED * const ptrMed,
32                                MED_EN::med_mode_acces accessMode):
33   GENDRIVER(fileName,accessMode), _ptrMed(ptrMed), _medIdt(MED_INVALID)
34 {
35 }
36 //REM :  As t'on besoin du champ _status :  _medIdt <-> _status  ?  Oui
37
38 MED_MED_DRIVER::MED_MED_DRIVER(const MED_MED_DRIVER & driver):
39   GENDRIVER(driver),
40   _ptrMed(driver._ptrMed),
41   _medIdt(MED_INVALID)
42 {
43 }
44
45 MED_MED_DRIVER::~MED_MED_DRIVER()
46 {
47   MESSAGE("MED_MED_DRIVER::~MED_MED_DRIVER() has been destroyed");
48 }
49
50 //  GENDRIVER * MED_MED_DRIVER::copy(void) const
51 //  {
52 //    return new MED_MED_DRIVER(*this) ;
53 //  }
54 void MED_MED_DRIVER::read()
55 {
56 }
57 void MED_MED_DRIVER::readFileStruct()
58 {
59 }
60 void MED_MED_DRIVER::write() const
61 {
62 }
63 GENDRIVER * MED_MED_DRIVER::copy(void) const
64 {
65   return new MED_MED_DRIVER(*this) ;
66 }
67 void MED_MED_DRIVER::writeFrom() const
68 {
69 }
70
71
72
73 void MED_MED_DRIVER::open()
74   throw (MEDEXCEPTION)
75 {
76
77   const char * LOC ="MED_MED_DRIVER::open() : ";
78   BEGIN_OF(LOC);
79
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()"
85 //                                       )
86 //                            );   
87   
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()"
92 //                                       )
93 //                            );
94   
95   if ( _fileName == "" )
96     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
97                                      << "_fileName is |\"\"|, please set a correct fileName before calling open()"
98                                      )
99                           );
100   
101   MESSAGE(LOC<<"_fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode);
102   _medIdt = MEDouvrir( (const_cast <char *> (_fileName.c_str())), (med_2_1::med_mode_acces) _accessMode);
103   MESSAGE(LOC<<" _medIdt = "<<_medIdt);
104   
105   if (_medIdt > 0) 
106     _status=MED_OPENED; 
107   else {
108     _status = MED_CLOSED;
109     _medIdt = MED_INVALID;
110     throw MED_EXCEPTION (LOCALIZED( STRING(LOC) 
111                                     << "Can't open |"  << _fileName 
112                                     << "|, _medIdt : " << _medIdt
113                                     )
114                          );
115   }
116
117   END_OF(LOC);
118 }
119
120
121 void MED_MED_DRIVER::close()
122 {
123   med_2_1::med_int err = 0;
124   const char * LOC = "MED_MED_DRIVER::close() : ";
125   
126   
127 //    if ( _status == MED_CLOSED)
128 //      throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << ": the file |" 
129 //                                       << _fileName << "| is already closed"
130 //                                       )
131 //                            );
132    
133 //    if ( _medIdt == MED_INVALID ) 
134 //      throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "_medIdt invalid, but the file |" 
135 //                                       << _fileName << "| seems to be openned !"
136 //                                       )
137 //                            );   
138
139   if ( _medIdt != MED_INVALID )
140     err=med_2_1::MEDfermer(_medIdt);
141   
142 //    if (err != MED_VALID) 
143 //      throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "the file |" 
144 //                                       << _fileName << "| couldn't be closed"
145 //                                       )
146 //                            );   
147   
148   _status = MED_CLOSED;
149   _medIdt = MED_INVALID;
150     
151   END_OF(LOC);
152 }
153
154
155 // ------------- Read Only Part --------------
156
157 MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER():MED_MED_DRIVER()
158 {
159 }
160
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)
163 {
164   MESSAGE("MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const string & fileName,  MED * const ptrMed) Constructeur read only");
165 }
166
167 MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const MED_MED_RDONLY_DRIVER & driver):
168   MED_MED_DRIVER(driver)
169 {
170 }
171
172 MED_MED_RDONLY_DRIVER::~MED_MED_RDONLY_DRIVER()
173 {
174   MESSAGE("MED_MED_RDONLY_DRIVER::~MED_MED_RDONLY_DRIVER() has been destroyed");
175
176
177 GENDRIVER * MED_MED_RDONLY_DRIVER::copy(void) const
178 {
179   return new MED_MED_RDONLY_DRIVER(*this) ;
180 }
181
182 void MED_MED_RDONLY_DRIVER::readFileStruct( void ) 
183   throw (MEDEXCEPTION)
184 {
185   const char * LOC = "MED_MED_DRIVER::readFileStruct() : ";
186   int          err,i,j;
187       
188   BEGIN_OF(LOC);
189
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()"
194                                      )
195                           );   
196   // Read number of meshes and their associated name
197   {
198     int          numberOfMeshes;
199     char         meshName[MED_TAILLE_NOM+1]="";
200     med_2_1::med_int          meshDim;
201     MESH *       ptrMesh;
202     //    MED_MESH_RDWR_DRIVER * ptrDriver; !! UNUSED VARIABLE !!
203     
204     numberOfMeshes = med_2_1::MEDnMaa(_medIdt) ;
205     if ( numberOfMeshes <= 0 ) 
206       MESSAGE(LOC << "Be careful there is no mesh in file |"<<_fileName<<"| !");
207
208     MESH_ENTITIES::const_iterator currentEntity; 
209     for (i=1;i<=numberOfMeshes;i++) {
210
211       // find out if the mesh is a Grid
212       
213       med_2_1::med_int isAGrid = false;
214       med_2_1::med_grid_type type;
215       
216       err = MEDgridInfo (_medIdt, i, &isAGrid, &type);
217       if (err != MED_VALID) 
218         throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "error in MEDgridInfo()") );
219
220       err = med_2_1::MEDmaaInfo(_medIdt, i ,meshName, &meshDim) ;
221       if (err != MED_VALID) 
222         throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << ": can't get information about the mesh n°"
223                                          << i <<" of the file |" << _fileName << "| !"
224                                          )
225                               );   
226       MESSAGE(LOC<<": Mesh n°"<<i<<" nammed "<<meshName);
227
228       if (isAGrid)
229         ptrMesh = new GRID((MED_EN::med_grid_type) type);
230       else
231         ptrMesh = new MESH();
232
233       //MED_MESH_RDWR_DRIVER * _ptrDriver = new MED_MESH_RDWR_DRIVER(_fileName, ptrMesh);
234       MED_EN::med_mode_acces myMode = getAccessMode();
235       MED_MESH_DRIVER * ptrDriver ;
236       switch (myMode) {
237       case MED_EN::MED_LECT:
238         ptrDriver = new MED_MESH_RDONLY_DRIVER(_fileName, ptrMesh);
239         break ;
240       case MED_EN::MED_REMP:    
241         ptrDriver = new MED_MESH_RDWR_DRIVER(_fileName, ptrMesh);
242         break ;
243       case MED_EN::MED_ECRI: // should never append !!
244         ptrDriver = new MED_MESH_RDONLY_DRIVER(_fileName, ptrMesh);
245         break;
246       default:
247         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
248       }
249       ptrDriver->setId       ( getId() );
250       ptrDriver->setMeshName ( meshName );
251       ptrMesh->addDriver(*ptrDriver);
252       delete ptrDriver ;
253
254       if (isAGrid)
255         _ptrMed->_meshes[meshName] = (MESH *) ptrMesh;
256       else
257         _ptrMed->_meshes[meshName] = ptrMesh;
258
259       ptrMesh->setName(meshName);
260
261       SCRUTE(ptrMesh);
262
263       MESSAGE(LOC<<"is" << (isAGrid ? "" : " NOT") << " a GRID and its name is "<<ptrMesh->getName());
264
265       // we create all global support (for each entity type :
266       int index = 0;
267       for (currentEntity=meshEntities.begin();currentEntity != meshEntities.end(); currentEntity++) {
268         string supportName="SupportOnAll_" ;
269         supportName+=entNames[(*currentEntity).first] ;
270         //(_ptrMed->_support)[meshName][(MED_EN::medEntityMesh)(*currentEntity).first]=new SUPPORT(ptrMesh,supportName,(MED_EN::medEntityMesh) (*currentEntity).first) ;
271         SUPPORT* mySupport = new SUPPORT() ;
272         mySupport->setName(supportName);
273         mySupport->setMesh(ptrMesh);
274         mySupport->setEntity((MED_EN::medEntityMesh) (*currentEntity).first);
275         mySupport->setAll(true);
276         (_ptrMed->_support)[meshName][(MED_EN::medEntityMesh)(*currentEntity).first] = mySupport ;
277         MESSAGE(LOC<< "The support " << supportName.c_str() << " on entity " << (*currentEntity).first << " is built");
278         index++;
279       }
280       MESSAGE(LOC <<"The mesh " <<ptrMesh->getName() << " has " << index << " support(s)");
281     }
282
283     map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> >::const_iterator const_itSupportOnMesh ;
284
285     int index = 0;
286
287     vector<SUPPORT *> vectSupp;
288     for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
289          const_itSupportOnMesh++ )
290       {
291         map<MED_EN::medEntityMesh,SUPPORT *>::const_iterator const_itSupport ;
292         for (const_itSupport=(*const_itSupportOnMesh).second.begin();
293              const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++) index++;
294       }
295
296     MESSAGE(LOC << "In this MED object there is(are) " << index << " support(s):");
297
298     vectSupp.resize(index);
299
300     index = 0;
301     for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
302          const_itSupportOnMesh++ )
303       {
304         map<MED_EN::medEntityMesh,SUPPORT *>::const_iterator const_itSupport ;
305         for (const_itSupport=(*const_itSupportOnMesh).second.begin();
306              const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++)
307           {
308             vectSupp[index] = (*const_itSupport).second;
309             SCRUTE(vectSupp[index]);
310             MESSAGE(LOC << "Support number " << index << " is "<< *vectSupp[index]);
311             index++;
312           }
313       }
314
315   }
316   
317   
318   // Read number of fields, their associated name and their list of (timeStepNumber,iterationNumber)
319   {
320     int                           numberOfFields              = 0;      //MED_INVALID
321     //    char                          fieldName[MED_TAILLE_NOM+1] = "";
322     char                          fieldName[MED_TAILLE_NOM+1] ;
323     int                           numberOfComponents           = 0;
324     char                          * componentName              = (char *) MED_NULL;
325     char                          * unitName                   =  (char *) MED_NULL;
326     //    char                          meshName[MED_TAILLE_NOM+1]  = "";
327     char                          meshName[MED_TAILLE_NOM+1]  ;
328     med_2_1::med_type_champ        type;
329     MESH                          * ptrMesh                        = (MESH  *) MED_NULL;
330     FIELD_                        * ptrField                       = (FIELD_ *) MED_NULL;
331     //MED_FIELD_RDWR_DRIVER         * ptrDriver                      = (MED_FIELD_RDWR_DRIVER * ) MED_NULL;
332     GENDRIVER                     * ptrDriver                      = (GENDRIVER * ) MED_NULL;
333     SUPPORT                       * ptrSupport                     = (SUPPORT *   ) MED_NULL;
334     MESH_ENTITIES::const_iterator currentEntity; 
335     list<MED_EN::medGeometryElement>::const_iterator currentGeometry;
336     med_2_1::med_int                           NbOfGaussPts                 =  0;
337     int                           numberOfTimeSteps            =  -1;
338     med_2_1::med_int                           timeStepNumber               =  -1;
339     //    char                          timeStepUnit[MED_TAILLE_PNOM]= "";
340     char                          timeStepUnit[MED_TAILLE_PNOM+1] ;
341     double                        timeStep                     = 0.0;
342     med_2_1::med_int                           orderNumber                  =  -1;                           //???init?????
343     map<MESH_NAME_,MESH*>      & _meshes   =  _ptrMed->_meshes; 
344     map<FIELD_NAME_,MAP_DT_IT_> & _fields   =  _ptrMed->_fields; 
345     map<FIELD_ *, MESH_NAME_>  & _meshName =  _ptrMed->_meshName; 
346     map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> > & _support = _ptrMed->_support;
347
348     
349     numberOfFields = med_2_1::MEDnChamp(_medIdt,0) ;
350     if ( numberOfFields <= 0 ) 
351       MESSAGE(LOC << "Be careful there is no field in file |"<<_fileName<<"| !");
352   
353     for (i=1;i<=numberOfFields;i++) {
354
355       numberOfComponents = med_2_1::MEDnChamp(_medIdt,i) ;
356       if ( numberOfComponents <= 0 ) 
357         if (err != MED_VALID) 
358           throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) <<  "Be careful there is no compound for field n°" 
359                                            << i << "in file |"<<_fileName<<"| !"));
360       
361       componentName = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;
362       unitName      = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;   
363       
364       err = MEDchampInfo(_medIdt, i, fieldName, &type, componentName, 
365                          unitName, numberOfComponents) ;
366
367       if (err != MED_VALID) 
368         throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
369                                          << ": can't get information about the field n°"
370                                          << i <<" of the file |" << _fileName << "| !")); 
371       
372       MESSAGE(LOC << "Field n°"<<i<<" nammed "<< fieldName 
373               << " ,component(s)  : " << componentName 
374               <<" ,unit(s) : "        << unitName);
375       
376
377       // Loop on all (entity type,geometry type) until you find an existing one then
378       // get the (n°dt,n°it) pairs list for the current (field,entity type,geometry type)
379       // We suppose there is the same list whatever the existing (entity type,geometry type) pair  
380       // support map :
381       for (currentEntity=meshEntities.begin();currentEntity != meshEntities.end(); currentEntity++) { 
382         //         numberOfTimeSteps  MUST be given by MEDchampInfo !!!!!
383         for (currentGeometry  = (*currentEntity).second.begin();currentGeometry != (*currentEntity).second.end(); currentGeometry++) {
384           MESSAGE("Field information with Entity,Geom = "<<(*currentEntity).first<<","<<(*currentGeometry));
385           numberOfTimeSteps = MEDnPasdetemps(_medIdt, fieldName,
386                                              (med_2_1::med_entite_maillage)(*currentEntity).first,
387                                              (med_2_1::med_geometrie_element) (*currentGeometry) );
388           MESSAGE("Field information 2 : NumberOfTimeStep :"<<numberOfTimeSteps);
389           if ( numberOfTimeSteps > MED_VALID ) 
390             break ; // There are value for some med_geometrie_element of this med_entite_maillage.
391         }
392         if (numberOfTimeSteps>0) // we have at least one
393           
394           for (currentGeometry  = (*currentEntity).second.begin();currentGeometry != (*currentEntity).second.end(); currentGeometry++) {            
395             
396             MESSAGE("Field information 3 : Geom : "<<(*currentGeometry));
397             for (j=1;j <= numberOfTimeSteps; j++) {
398               
399               MESSAGE("Field information 4 : time step j = "<<j);
400               err = MEDpasdetempsInfo( _medIdt, fieldName,
401                                        (med_2_1::med_entite_maillage) (*currentEntity).first, 
402                                        (med_2_1::med_geometrie_element) (*currentGeometry),j, 
403                                        meshName, &NbOfGaussPts,
404                                        &timeStepNumber, timeStepUnit, &timeStep,
405                                        &orderNumber);
406               if (err == MED_VALID) { // we have found for (*currentEntity).first and (*currentGeometry)
407                 
408                 MESSAGE("Field information 5 ;: NumberOfGaussPoint : "<<NbOfGaussPts<<", timeStepNumber : "<<timeStepNumber);
409                 // CORRECT a bug in MEDpasdetempsInfo :
410                 // we get a value n'importe quoi in NbOfGaussPts !!!!
411                 
412                 if (NbOfGaussPts>100)
413                   NbOfGaussPts=1 ;
414                 if (timeStepNumber<0)
415                   timeStepNumber=-1 ;
416                 
417                 
418                 // ATTENTION TRAITER L'EXCEPTION !!!!!!!!!!!!
419                 
420                 // Il faudra traiter le cas d'un champ qui utilise +sieurs (entity,geom) voir le travail de patrick
421                 // Il faudra traiter le cas des profils...
422                 //             ptrField = new FIELD();
423                 //             _ptrDriver = new MED_FIELD_RDWR_DRIVER(_fileName, ptrField);
424                 //             ptrField->addDriver(_ptrDriver);
425                 //             _fields[fieldName]=ptrField;
426                 
427                 // Verify meshName is already known
428                 
429                 map<MESH_NAME_,MESH*>::iterator _meshesIt = _meshes.find(meshName);
430                 if ( _meshesIt == _meshes.end() ) {
431                   MESSAGE(LOC << "There is no mesh |"
432                           << meshName                            <<"| in the file |"
433                           << _fileName <<"|, but  |" << meshName <<"| is referenced by field |"
434                           << fieldName                           <<"|, entity : |"
435                           << entNames [(*currentEntity).first] <<"|, geometric element of type |" 
436                           << geoNames [(*currentGeometry)]     <<"|" 
437                           ); 
438                 }  // POURQUOI SI JE NE MET PAS DE BLOCK J'AI UN PARSE ERROR : PG : c'est la macro MESSAGE qui fait ca !
439                 else 
440                   ptrMesh = _meshes[meshName];
441                 
442                 ptrSupport     =  _support[meshName][(med_2_1::med_entite_maillage) (*currentEntity).first];
443                 if (NbOfGaussPts != 1)
444                   throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<"Number of Gauss Point must be equal to 1 for instance")) ;
445                 
446                 // init to null to prevent some error if not correctly allocated !
447                 ptrField = (FIELD_*)NULL ;
448                 ptrDriver = (GENDRIVER*)NULL ;
449
450                 switch ( type) {
451                 case med_2_1::MED_INT64 :
452                   if ( sizeof(med_2_1::med_int) != 8 )
453                     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) <<
454                                                      " The Field type of |"
455                                                      << fieldName                         <<"|, entity : |"
456                                                      << entNames [(*currentEntity).first] <<"|, geometric element of type |" 
457                                                      << geoNames [(*currentGeometry) ]    <<
458                                                      "| is  MED_INT64 but size of med_int is not equal to 8 bytes !" 
459                                                      ) 
460                                           );
461                   break;
462                 case med_2_1::MED_INT32 : {
463 //                throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) <<
464 //                                                 "NOT IMPLEMENTED : BUG IN STL !")
465 //                                      ) ;
466                   // ptrField       =  new FIELD<med_2_1::med_int>   ( ptrSupport,numberOfComponents );   // Les valeurs du champ ne doivent pas être lue pour l'instant
467
468                   ptrField       =  new FIELD<int> ( );   // Les valeurs du champ ne doivent pas être lue pour l'instant
469                   ((FIELD<int>*) ptrField)->setSupport(ptrSupport);
470                   ((FIELD<int>*) ptrField)->setNumberOfComponents(numberOfComponents);
471                   ((FIELD<int>*) ptrField)->setName(fieldName) ; //provisoire, pour debug
472                   MESSAGE("#### SET NAME in FIELD : "<<fieldName);
473
474                   MED_EN::med_mode_acces myMode = getAccessMode();
475                   switch (myMode) {
476                   case MED_EN::MED_LECT:
477                     ptrDriver = new MED_FIELD_RDONLY_DRIVER<int>(_fileName, (FIELD<int> *)ptrField);
478                     break ;
479                   case MED_EN::MED_REMP:        
480                     ptrDriver = new MED_FIELD_RDWR_DRIVER<int>(_fileName, (FIELD<int> *)ptrField);
481                     break ;
482                   case MED_EN::MED_ECRI: // should never append !!
483                     ptrDriver = new MED_FIELD_RDONLY_DRIVER<int>(_fileName, (FIELD<int> *)ptrField);
484                     break;
485                   default:
486                     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
487                   }
488                   break;
489                 }
490                 case med_2_1::MED_REEL64 : {
491                   //              ptrField       =  new FIELD<med_2_1::med_float> ( ptrSupport,numberOfComponents );   // Les valeurs du champ ne doivent pas être lue pour l'instant
492                   ptrField       =  new FIELD<med_2_1::med_float> ( );   // Les valeurs du champ ne doivent pas être lue pour l'instant
493                   ((FIELD<med_2_1::med_float>*) ptrField)->setSupport(ptrSupport);
494                   ((FIELD<med_2_1::med_float>*) ptrField)->setNumberOfComponents(numberOfComponents);
495                   ((FIELD<med_2_1::med_float>*) ptrField)->setName(fieldName) ; //provisoire, pour debug
496                   MESSAGE("#### SET NAME in FIELD : "<<fieldName);
497
498                   MED_EN::med_mode_acces myMode = getAccessMode();
499                   switch (myMode) {
500                   case MED_EN::MED_LECT:
501                     ptrDriver = new MED_FIELD_RDONLY_DRIVER<med_2_1::med_float>(_fileName, (FIELD<med_2_1::med_float> *)ptrField);
502                     break ;
503                   case MED_EN::MED_REMP:        
504                     ptrDriver = new MED_FIELD_RDWR_DRIVER<med_2_1::med_float>(_fileName, (FIELD<med_2_1::med_float> *)ptrField);
505                     break ;
506                   case MED_EN::MED_ECRI: // should never append !!
507                     ptrDriver = new MED_FIELD_RDONLY_DRIVER<med_2_1::med_float>(_fileName, (FIELD<med_2_1::med_float> *)ptrField);
508                     break;
509                   default:
510                     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
511                   }
512                   break;
513                 }
514                 default : {
515                   if ( numberOfTimeSteps > 1) 
516                     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) <<
517                                                      " The Field type of |"
518                                                      << fieldName                         <<"|, entity : |"
519                                                      << entNames [(*currentEntity).first] 
520                                                      <<"|, geometric element of type |" 
521                                                      << geoNames [(*currentGeometry)]     
522                                                      <<"| is neither MED_INT, MED_INT32, MED_INT64 nor MED_REEL64 !" 
523                                                      ) 
524                                           );
525                   break ;
526                 }
527                 }
528                 ptrField->setValueType((MED_EN::med_type_champ) type) ; // need to write field !
529                 
530                 MESSAGE("timeStepNumber :"<<timeStepNumber<<",orderNumber :"<<orderNumber);
531                 ptrField->setIterationNumber ( timeStepNumber);      // A ajouter dans la classe FIELD
532                 ptrField->setOrderNumber     ( orderNumber); 
533                 ptrField->setTime            ( timeStep); 
534                 
535                 // Create a driver for this (field n°dt,n°it)
536                 ptrDriver->setId            ( getId() );
537                 MESSAGE("###### ptrDriver->setFieldName : #"<<fieldName<<"#");
538                 ptrDriver->setFieldName(fieldName);
539                 ptrField->addDriver(*ptrDriver);
540                 // driver is duplicated : remove it
541                 delete ptrDriver;
542
543                 DT_IT_ dtIt;
544                 dtIt.dt  = timeStepNumber;
545                 dtIt.it  = orderNumber;
546                 
547                 (_fields  [fieldName])[dtIt] = ptrField;
548                 _meshName[ptrField ]       = meshName;
549               }
550             }
551           }
552       }
553       delete[] componentName ;
554       delete[] unitName ;
555     }
556   }
557   
558   // read profil count and their names
559   //  int support_count_= 0 ; !! UNUSED VARIABLE !!
560   // il faut lire les champs pour avoir les profils stockes !!!
561   // il faudrait implémenter la lecture des profils dans med !!!
562   
563   END_OF(LOC);
564   
565 }
566
567 // This method ask the drivers of all MESH/FIELD objects created from this MED driver
568 // to read themselves
569 void MED_MED_RDONLY_DRIVER::read( void )
570   throw (MEDEXCEPTION) // from objects method read !
571 {
572   const char * LOC = "MED_MED_DRIVER::read() : ";
573  
574   BEGIN_OF(LOC);
575
576   const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes); 
577   map<MESH_NAME_,MESH*>::const_iterator  currentMesh;
578
579   const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
580   map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
581   
582   for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) 
583     (*currentMesh).second->read(*this); 
584   //(*currentMesh).second->read(); // default reader, from readFileStruct
585     
586   // PROVISOIRE
587   _ptrMed->updateSupport() ;
588
589   for ( currentField =_meshName.begin(); currentField != _meshName.end(); currentField++ )
590     (*currentField).first->read(*this);
591   //(*currentField).first->read(); // default reader, from readFileStruct
592
593   END_OF(LOC);
594 }
595
596 void MED_MED_RDONLY_DRIVER::write(void) const
597   throw (MEDEXCEPTION)
598 {
599   throw MEDEXCEPTION("MED_MED_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");
600 }
601
602 void MED_MED_RDONLY_DRIVER::writeFrom(void) const
603   throw (MEDEXCEPTION)
604 {
605   throw MEDEXCEPTION("MED_MED_RDONLY_DRIVER::writeFrom : Can't write with a RDONLY driver !");
606 }
607
608 // ------------- Write Only Part --------------
609
610 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER():MED_MED_DRIVER()
611 {
612 }
613
614 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER(const string & fileName,  MED * const ptrMed):
615   MED_MED_DRIVER(fileName,ptrMed)
616 {}
617
618 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER(const MED_MED_WRONLY_DRIVER & driver):
619   MED_MED_DRIVER(driver)
620 {}
621
622 MED_MED_WRONLY_DRIVER::~MED_MED_WRONLY_DRIVER()
623 {
624   MESSAGE("MED_MED_WRONLY_DRIVER::~MED_MED_WRONLY_DRIVER() has been destroyed");
625
626
627 GENDRIVER * MED_MED_WRONLY_DRIVER::copy(void) const
628 {
629   return new MED_MED_WRONLY_DRIVER(*this) ;
630 }
631
632 void MED_MED_WRONLY_DRIVER::read(void)
633   throw (MEDEXCEPTION)
634 {
635   throw MEDEXCEPTION("MED_MED_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
636 }
637
638 void MED_MED_WRONLY_DRIVER::readFileStruct(void)
639   throw (MEDEXCEPTION)
640 {
641   throw MEDEXCEPTION("MED_MED_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
642 }
643
644 // This method ask the drivers of all MESH/FIELD objects created from this MED driver
645 // to write themselves
646 void MED_MED_WRONLY_DRIVER::writeFrom( void) const
647   throw (MEDEXCEPTION) //from object method write !
648 {
649   const char * LOC = "MED_MED_DRIVER::writeFrom() : ";
650
651   BEGIN_OF(LOC);
652
653   const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes); 
654   map<MESH_NAME_,MESH*>::const_iterator  currentMesh;
655
656   const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
657   map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
658   
659   for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
660     try {
661       (*currentMesh).second->write(*this); 
662       // On utilise pour les objects MESH ET FIELD le write(GENDRIVER *) et le == ds GENDRIVER avec eventuellement 1 id 
663     }
664     catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) {
665       continue;
666     }
667   }
668
669   for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
670     try {
671       (*currentField).first->write(*this);
672     }
673     catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) {
674       continue;
675     }
676   }
677
678   END_OF(LOC);
679
680 }
681
682 void MED_MED_WRONLY_DRIVER::write(void ) const
683   throw (MEDEXCEPTION) // from object method write !
684 {
685   const char * LOC = "MED_MED_DRIVER::write() : ";
686   int current;
687
688   BEGIN_OF(LOC);
689
690   // BCLE SUR LES OBJETS AVEC AJOUT DE DRIVER ET APPELS write
691
692   const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes); 
693   map<MESH_NAME_,MESH*>::const_iterator  currentMesh;
694
695   const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
696   map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
697   
698   for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
699     //current = (*currentMesh).second->addDriver(MED_DRIVER,_fileName);
700     current = (*currentMesh).second->addDriver(MED_DRIVER,_fileName,(*currentMesh).second->getName());
701     // put right _id in Mesh driver (same as this._id)
702     (*currentMesh).second->_drivers[current]->setId( getId() );
703     //(*currentMesh).second->write(current) ;
704   }
705
706   for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
707     //current = (*currentField).first->addDriver(MED_DRIVER,_fileName);
708     current = (*currentField).first->addDriver(MED_DRIVER,_fileName,(*currentField).first->getName());
709     // put right _id in Field driver (same as this._id)
710     (*currentField).first->_drivers[current]->setId( getId() );
711     //(*currentField).first->write(current) ;
712   }
713
714   // that's work, but it is more efficenty to write directly when we had driver, no ?
715   writeFrom();
716   
717   END_OF(LOC);
718
719 }
720
721 // ------------- Read Write Part --------------
722
723 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER()
724 {}
725
726 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER(const string & fileName,  MED * const ptrMed):
727   MED_MED_DRIVER(fileName,ptrMed)
728 {}
729
730 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER(const MED_MED_RDWR_DRIVER & driver):
731   MED_MED_DRIVER(driver)
732 {}
733
734 MED_MED_RDWR_DRIVER::~MED_MED_RDWR_DRIVER() { 
735   MESSAGE("MED_MED_RDWR_DRIVER::~MED_MED_RDWR_DRIVER() has been destroyed");
736 }
737
738 GENDRIVER * MED_MED_RDWR_DRIVER::copy(void) const
739 {
740   return new MED_MED_RDWR_DRIVER(*this) ;
741 }
742
743 void MED_MED_RDWR_DRIVER::read(void)
744   throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::read()
745 {
746   BEGIN_OF("MED_MED_RDWR_DRIVER::read(void)");
747   MED_MED_RDONLY_DRIVER::read();
748   END_OF("MED_MED_RDWR_DRIVER::read(void)");
749 }
750
751 void MED_MED_RDWR_DRIVER::readFileStruct(void)
752   throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::readFileStruct()
753 {
754   BEGIN_OF("MED_MED_RDWR_DRIVER::readFileStruct(void)");
755   MED_MED_RDONLY_DRIVER::readFileStruct();
756   END_OF("MED_MED_RDWR_DRIVER::readFileStruct(void)");
757 }
758
759 void MED_MED_RDWR_DRIVER::write(void) const
760   throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::write()
761 {
762   BEGIN_OF("MED_MED_RDWR_DRIVER::write(void) const");
763   MED_MED_WRONLY_DRIVER::write();
764   END_OF("MED_MED_RDWR_DRIVER::write(void) const");
765 }
766
767 void MED_MED_RDWR_DRIVER::writeFrom(void) const
768   throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::writeFrom();
769 {
770   BEGIN_OF("MED_MED_RDWR_DRIVER::writeFrom(void) const");
771   MED_MED_WRONLY_DRIVER::writeFrom();
772   END_OF("MED_MED_RDWR_DRIVER::writeFrom(void) const");
773 }