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