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