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