]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_MedMedDriver.cxx
Salome HOME
correct small problem from the version in the MedFileV2_2 branch.
[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 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_FR::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_FR::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=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     char         meshDescription[MED_TAILLE_DESC+1]="";
201     int          meshDim;
202     MED_FR::med_maillage meshType;
203
204     MESH *       ptrMesh;
205     //    MED_MESH_RDWR_DRIVER * ptrDriver; !! UNUSED VARIABLE !!
206     
207     numberOfMeshes = MEDnMaa(_medIdt) ;
208     if ( numberOfMeshes <= 0 ) 
209       MESSAGE(LOC << "Be careful there is no mesh in file |"<<_fileName<<"| !");
210
211     MESH_ENTITIES::const_iterator currentEntity; 
212     for (i=1;i<=numberOfMeshes;i++)
213       {
214         //get infoamation on the i^th mesh
215
216         err = MEDmaaInfo(_medIdt, i ,meshName, &meshDim, &meshType,
217                          meshDescription) ;
218
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 << "| !"));
221
222         switch (meshType)
223           {
224           case MED_FR::MED_STRUCTURE:
225             MESSAGE(LOC<<": Mesh n°"<< i <<" nammed "<< meshName << " with the description " << meshDescription << " is structured");
226
227             MED_FR::med_type_grille type;
228
229             err = MEDnatureGrilleLire(_medIdt, meshName, &type);
230
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 << "| !"));
233
234             ptrMesh = new GRID((MED_EN::med_type_grille) type);
235             break;
236           case MED_FR::MED_NON_STRUCTURE:
237             MESSAGE(LOC<<": Mesh n°"<< i <<" nammed "<< meshName << " with the description " << meshDescription << " is not structured");
238
239             ptrMesh = new MESH();
240             break;
241           default:
242             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mesh type !"));
243           }
244
245 //      // find out if the mesh is a Grid
246       
247         bool isAGrid = ptrMesh->getIsAGrid();
248
249 //      MED_FR::med_grid_type type;
250       
251 //      err = MEDgridInfo (_medIdt, i, &isAGrid, &type);
252 //      if (err != MED_VALID) 
253 //        throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "error in MEDgridInfo()") );
254
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 << "| !"
259 //                                         )
260 //                              );   
261 //      MESSAGE(LOC<<": Mesh n°"<<i<<" nammed "<<meshName);
262
263 //      if (isAGrid)
264 //        ptrMesh = new GRID((MED_EN::med_grid_type) type);
265 //      else
266 //        ptrMesh = new MESH();
267
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 ;
271         switch (myMode) {
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);
275           break ;
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);
279           break ;
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);
284           break;
285         case MED_EN::MED_CREATION: // V2_1->V2_2
286           ptrDriver = new MED_MESH_WRONLY_DRIVER(_fileName, ptrMesh);
287           break;
288         default:
289           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
290         }
291         ptrDriver->setId       ( getId() );
292         ptrDriver->setMeshName ( meshName );
293         ptrMesh->addDriver(*ptrDriver);
294         delete ptrDriver ;
295
296         if (isAGrid)
297           _ptrMed->_meshes[meshName] = (MESH *) ptrMesh;
298         else
299           _ptrMed->_meshes[meshName] = ptrMesh;
300
301         _ptrMed->_meshes[meshName] = ptrMesh;
302
303         ptrMesh->setName(meshName);
304
305         ptrMesh->setDescription(meshDescription);
306
307         SCRUTE(ptrMesh);
308
309         MESSAGE(LOC<<"is" << (isAGrid ? "" : " NOT") << " a GRID and its name is "<<ptrMesh->getName());
310
311         // we create all global support (for each entity type :
312         int index = 0;
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");
324           index++;
325         }
326         MESSAGE(LOC <<"The mesh " <<ptrMesh->getName() << " has " << index << " support(s)");
327       }
328
329     map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::const_iterator const_itSupportOnMesh ;
330
331     int index = 0;
332
333     vector<SUPPORT *> vectSupp;
334     for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
335          const_itSupportOnMesh++ )
336       {
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++;
340       }
341
342     MESSAGE(LOC << "In this MED object there is(are) " << index << " support(s):");
343
344     vectSupp.resize(index);
345
346     index = 0;
347     for (const_itSupportOnMesh=_ptrMed->_support.begin(); const_itSupportOnMesh != _ptrMed->_support.end();
348          const_itSupportOnMesh++ )
349       {
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++)
353           {
354             vectSupp[index] = (*const_itSupport).second;
355             SCRUTE(vectSupp[index]);
356             MESSAGE(LOC << "Support number " << index << " is "<< *vectSupp[index]);
357             index++;
358           }
359       }
360
361   }
362   
363   
364   // Read number of fields, their associated name and their list of (timeStepNumber,iterationNumber)
365   {
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;
395
396     numberOfFields = MEDnChamp(_medIdt,0) ;
397     if ( numberOfFields <= 0 ) 
398       MESSAGE(LOC << "Be careful there is no field in file |"<<
399               _fileName<<"| !");
400
401     for (i=1;i<=numberOfFields;i++)
402       {
403         numberOfComponents = MEDnChamp(_medIdt,i) ;
404
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<<"| !"));
408
409         componentName = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;
410         unitName      = new char[numberOfComponents*MED_TAILLE_PNOM+1] ;   
411       
412         err = MEDchampInfo(_medIdt, i, fieldName, &type, componentName, 
413                            unitName, numberOfComponents) ;
414
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 << "| !")); 
417
418         MESSAGE(LOC << "Field n°"<<i<<" nammed "<< fieldName 
419                 << " ,component(s)  : " << componentName 
420                 <<" ,unit(s) : "        << unitName);
421
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 
426
427         // support map :
428
429         for (currentEntity=meshEntities.begin();currentEntity != meshEntities.end(); currentEntity++)
430           { 
431             //         numberOfTimeSteps  MUST be given by MEDchampInfo !!!!!
432             for (currentGeometry  = (*currentEntity).second.begin();
433                  currentGeometry != (*currentEntity).second.end();
434                  currentGeometry++)
435               {
436                 MESSAGE("Field information with Entity,Geom = "<<
437                         (*currentEntity).first<<","<<(*currentGeometry));
438
439                 numberOfTimeSteps =
440                   MEDnPasdetemps(_medIdt, fieldName,
441                                  (MED_FR::med_entite_maillage)(*currentEntity).first,
442                                  (MED_FR::med_geometrie_element) (*currentGeometry) );
443
444                 MESSAGE("Field information 2 : NumberOfTimeStep :"<<
445                         numberOfTimeSteps);
446
447                 if ( numberOfTimeSteps > MED_VALID ) 
448                   break ;
449                 // There are value for some med_geometrie_element of this
450                 // med_entite_maillage.
451               }
452             if (numberOfTimeSteps>0) // we have at least one
453           
454               for (currentGeometry = (*currentEntity).second.begin();
455                    currentGeometry != (*currentEntity).second.end();
456                    currentGeometry++)
457                 {
458                   MESSAGE("Field information 3 : Geom : "<<(*currentGeometry));
459
460                   for (j=1;j <= numberOfTimeSteps; j++)
461                     {
462                       MESSAGE("Field information 4 : time step j = "<<j);
463
464                       // err = MEDpasdetempsInfo( _medIdt, fieldName,
465                       // (MED_FR::med_entite_maillage) (*currentEntity).first, 
466                       // (*currentGeometry),j, meshName,
467                       // &NbOfGaussPts, &timeStepNumber,
468                       // timeStepUnit, &timeStep, &orderNumber);
469
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,
478                                               &numberOfRefMesh);
479
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 !!!!
486
487                           if (timeStepNumber<0)  timeStepNumber=-1 ;
488                           if ((numberOfRefMesh != 1) ||
489                               (meshLink != MED_FR::MED_VRAI) ||
490                               (NbOfGaussPts != 1))
491                             {
492                               NbOfGaussPts = 1;
493                               numberOfRefMesh=1;
494                               meshLink != MED_FR::MED_VRAI;
495                               MESSAGE("This field is Med Memory compliant because NumberOfGaussPoint : " << NbOfGaussPts << ", or  numberOfRefMesh : " << numberOfRefMesh << ", or meshLink : " << meshLink);
496                             }
497
498                           // ATTENTION TRAITER L'EXCEPTION CI DESSUS !!!!!!!!
499                 
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,
505                           //                                        ptrField);
506                           // ptrField->addDriver(_ptrDriver);
507                           // _fields[fieldName]=ptrField;
508                 
509                           // Verify meshName is already known
510                 
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)]     <<"|"); 
524                           }
525                           // POURQUOI SI JE NE MET PAS DE BLOCK J'AI UN PARSE
526                           // ERROR : PG : c'est la macro MESSAGE qui fait ca !
527                           else
528                             ptrMesh = _meshes[meshName];
529
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")) ;
533
534                           // init to null to prevent some error if not
535                           // correctly allocated !
536
537                           ptrField = (FIELD_*)NULL ;
538                           ptrDriver = (GENDRIVER*)NULL ;
539
540                           switch ( type) {
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 !"));
544                             break;
545                           case MED_FR::MED_INT32 : {
546                             // throw MED_EXCEPTION(LOCALIZED(STRING(LOC) <<
547                             // "NOT IMPLEMENTED : BUG IN STL !")
548                             //) ;
549                             // ptrField = new FIELD<MED_FR::med_int> (ptrSupport,numberOfComponents);
550                             // Les valeurs du champ ne doivent pas être lue
551                             // pour l'instant
552
553                             ptrField =  new FIELD<MED_FR::med_int> ( );
554                             // Les valeurs du champ ne doivent pas être lue
555                             // pour l'instant
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);
564
565                             MED_EN::med_mode_acces myMode = getAccessMode();
566                             switch (myMode) {
567                               // case MED_EN::MED_LECT: V2_1->V2_2
568                             case MED_EN::MED_LECTURE:
569                               ptrDriver = new
570                                 MED_FIELD_RDONLY_DRIVER<MED_FR::med_int>
571                                 (_fileName, (FIELD<MED_FR::med_int> *)
572                                  ptrField);
573                               break ;
574                               // case MED_EN::MED_REMP: V2_1->V2_2
575                             case MED_EN::MED_LECTURE_ECRITURE:  
576                               ptrDriver = new
577                                 MED_FIELD_RDWR_DRIVER<MED_FR::med_int>
578                                 (_fileName, (FIELD<MED_FR::med_int> *)
579                                  ptrField);
580                               break ;
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 !!
585                               // ptrDriver = new
586                               // MED_FIELD_RDONLY_DRIVER<MED_FR::med_int>
587                               // (_fileName, (FIELD<MED_FR::med_int> *)
588                               // ptrField);
589                               ptrDriver = new
590                                 MED_FIELD_WRONLY_DRIVER<MED_FR::med_int>
591                                 (_fileName, (FIELD<MED_FR::med_int> *)
592                                  ptrField);
593                               break;
594                             case MED_EN::MED_CREATION: // V2_1->V2_2
595                               ptrDriver = new
596                                 MED_FIELD_WRONLY_DRIVER<MED_FR::med_int>
597                                 (_fileName, (FIELD<MED_FR::med_int> *)
598                                  ptrField);
599                               break;
600                             default:
601                               throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
602                             }
603                             break;
604                           }
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
609                             // pour l'instant
610                             ptrField = new FIELD<MED_FR::med_float> ( );
611                             // Les valeurs du champ ne doivent pas être lue
612                             // pour l'instant
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);
621
622                             MED_EN::med_mode_acces myMode = getAccessMode();
623                             switch (myMode) {
624                               // case MED_EN::MED_LECT: V2_1->V2_2
625                             case MED_EN::MED_LECTURE:
626                               ptrDriver = new
627                                 MED_FIELD_RDONLY_DRIVER<MED_FR::med_float>
628                                 (_fileName, (FIELD<MED_FR::med_float> *)
629                                  ptrField);
630                               break ;
631                               // case MED_EN::MED_REMP: V2_1->V2_2
632                             case MED_EN::MED_LECTURE_ECRITURE:
633                               ptrDriver = new
634                                 MED_FIELD_RDWR_DRIVER<MED_FR::med_float>
635                                 (_fileName, (FIELD<MED_FR::med_float> *)
636                                  ptrField);
637                               break ;
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 !!
642                               // ptrDriver = new
643                               // MED_FIELD_RDONLY_DRIVER<MED_FR::med_float>
644                               // (_fileName, (FIELD<MED_FR::med_float> *)
645                               // ptrField);
646                               ptrDriver = new
647                                 MED_FIELD_WRONLY_DRIVER<MED_FR::med_float>
648                                 (_fileName, (FIELD<MED_FR::med_float> *)
649                                  ptrField);
650                               break;
651                             case MED_EN::MED_CREATION:
652                               // should never append !!
653                               ptrDriver = new
654                                 MED_FIELD_WRONLY_DRIVER<MED_FR::med_float>
655                                 (_fileName, (FIELD<MED_FR::med_float> *)
656                                  ptrField);
657                               break;
658                             default:
659                               throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access !"));
660                   }
661                             break;
662                           }
663                           default : {
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 !"));
666                             break ;
667                           }
668                           }
669                           ptrField->setValueType((MED_EN::med_type_champ)
670                                                  type) ;
671                           // need to write field !
672                 
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); 
679                 
680                           // Create a driver for this (field n°dt,n°it)
681                           ptrDriver->setId            ( getId() );
682                           MESSAGE("###### ptrDriver->setFieldName : #"<<
683                                   fieldName<<"#");
684                           ptrDriver->setFieldName(fieldName);
685                           ptrField->addDriver(*ptrDriver);
686                           // driver is duplicated : remove it
687                           delete ptrDriver;
688
689                           DT_IT_ dtIt;
690                           dtIt.dt  = timeStepNumber;
691                           dtIt.it  = orderNumber;
692                 
693                           (_fields  [fieldName])[dtIt] = ptrField;
694                           _meshName[ptrField ]       = meshName;
695                         }
696                     }
697                 }
698           }
699         delete[] componentName ;
700         delete[] unitName ;
701       }
702   }
703   
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 !!!
708   
709   END_OF(LOC);
710   
711 }
712
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 !
717 {
718   const char * LOC = "MED_MED_DRIVER::read() : ";
719  
720   BEGIN_OF(LOC);
721
722   const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes); 
723   map<MESH_NAME_,MESH*>::const_iterator  currentMesh;
724
725   const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
726   map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
727   
728   for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) 
729     (*currentMesh).second->read(*this); 
730   //(*currentMesh).second->read(); // default reader, from readFileStruct
731     
732   // PROVISOIRE
733   _ptrMed->updateSupport() ;
734
735   for ( currentField =_meshName.begin(); currentField != _meshName.end(); currentField++ )
736     (*currentField).first->read(*this);
737   //(*currentField).first->read(); // default reader, from readFileStruct
738
739   END_OF(LOC);
740 }
741
742 void MED_MED_RDONLY_DRIVER::write(void) const
743   throw (MEDEXCEPTION)
744 {
745   throw MEDEXCEPTION("MED_MED_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");
746 }
747
748 void MED_MED_RDONLY_DRIVER::writeFrom(void) const
749   throw (MEDEXCEPTION)
750 {
751   throw MEDEXCEPTION("MED_MED_RDONLY_DRIVER::writeFrom : Can't write with a RDONLY driver !");
752 }
753
754 // ------------- Write Only Part --------------
755
756 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER():MED_MED_DRIVER()
757 {
758 }
759
760 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER(const string & fileName,  MED * const ptrMed):
761   MED_MED_DRIVER(fileName,ptrMed)
762 {}
763
764 MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER(const MED_MED_WRONLY_DRIVER & driver):
765   MED_MED_DRIVER(driver)
766 {}
767
768 MED_MED_WRONLY_DRIVER::~MED_MED_WRONLY_DRIVER()
769 {
770   MESSAGE("MED_MED_WRONLY_DRIVER::~MED_MED_WRONLY_DRIVER() has been destroyed");
771
772
773 GENDRIVER * MED_MED_WRONLY_DRIVER::copy(void) const
774 {
775   return new MED_MED_WRONLY_DRIVER(*this) ;
776 }
777
778 void MED_MED_WRONLY_DRIVER::read(void)
779   throw (MEDEXCEPTION)
780 {
781   throw MEDEXCEPTION("MED_MED_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
782 }
783
784 void MED_MED_WRONLY_DRIVER::readFileStruct(void)
785   throw (MEDEXCEPTION)
786 {
787   throw MEDEXCEPTION("MED_MED_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
788 }
789
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 !
794 {
795   const char * LOC = "MED_MED_DRIVER::writeFrom() : ";
796
797   BEGIN_OF(LOC);
798
799   const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes); 
800   map<MESH_NAME_,MESH*>::const_iterator  currentMesh;
801
802   const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
803   map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
804   
805   for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
806     try {
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 
809     }
810     catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) {
811       continue;
812     }
813   }
814
815   for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
816     try {
817       (*currentField).first->write(*this);
818     }
819     catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) {
820       continue;
821     }
822   }
823
824   END_OF(LOC);
825
826 }
827
828 void MED_MED_WRONLY_DRIVER::write(void ) const
829   throw (MEDEXCEPTION) // from object method write !
830 {
831   const char * LOC = "MED_MED_DRIVER::write() : ";
832   int current;
833
834   BEGIN_OF(LOC);
835
836   // BCLE SUR LES OBJETS AVEC AJOUT DE DRIVER ET APPELS write
837
838   const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes); 
839   map<MESH_NAME_,MESH*>::const_iterator  currentMesh;
840
841   const map<FIELD_ *, MESH_NAME_> & _meshName = const_cast<const map<FIELD_ *, MESH_NAME_>& > (_ptrMed->_meshName);
842   map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
843   
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) ;
850   }
851
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) ;
858   }
859
860   // that's work, but it is more efficenty to write directly when we had driver, no ?
861   writeFrom();
862   
863   END_OF(LOC);
864
865 }
866
867 // ------------- Read Write Part --------------
868
869 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER()
870 {}
871
872 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER(const string & fileName,  MED * const ptrMed):
873   MED_MED_DRIVER(fileName,ptrMed)
874 {}
875
876 MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER(const MED_MED_RDWR_DRIVER & driver):
877   MED_MED_DRIVER(driver)
878 {}
879
880 MED_MED_RDWR_DRIVER::~MED_MED_RDWR_DRIVER() { 
881   MESSAGE("MED_MED_RDWR_DRIVER::~MED_MED_RDWR_DRIVER() has been destroyed");
882 }
883
884 GENDRIVER * MED_MED_RDWR_DRIVER::copy(void) const
885 {
886   return new MED_MED_RDWR_DRIVER(*this) ;
887 }
888
889 void MED_MED_RDWR_DRIVER::read(void)
890   throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::read()
891 {
892   BEGIN_OF("MED_MED_RDWR_DRIVER::read(void)");
893   MED_MED_RDONLY_DRIVER::read();
894   END_OF("MED_MED_RDWR_DRIVER::read(void)");
895 }
896
897 void MED_MED_RDWR_DRIVER::readFileStruct(void)
898   throw (MEDEXCEPTION) // from MED_MED_RDONLY_DRIVER::readFileStruct()
899 {
900   BEGIN_OF("MED_MED_RDWR_DRIVER::readFileStruct(void)");
901   MED_MED_RDONLY_DRIVER::readFileStruct();
902   END_OF("MED_MED_RDWR_DRIVER::readFileStruct(void)");
903 }
904
905 void MED_MED_RDWR_DRIVER::write(void) const
906   throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::write()
907 {
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");
911 }
912
913 void MED_MED_RDWR_DRIVER::writeFrom(void) const
914   throw (MEDEXCEPTION) // from MED_MED_WRONLY_DRIVER::writeFrom();
915 {
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");
919 }