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