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