]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Med.cxx
Salome HOME
update from the MedMemory V1.0.1
[modules/med.git] / src / MEDMEM / MEDMEM_Med.cxx
1 using namespace std;
2 # include <string> 
3
4 # include "MEDMEM_Med.hxx"
5  
6 # include "MEDMEM_STRING.hxx"
7
8 # include "MEDMEM_Mesh.hxx"
9 # include "MEDMEM_Grid.hxx"
10 # include "MEDMEM_Field.hxx"
11
12 # include "MEDMEM_Exception.hxx"
13 # include "utilities.h"
14
15 /*!
16   Constructor.
17 */
18 MED::MED() {
19   MESSAGE("MED::MED()");
20 };
21
22 /*!
23   Constructor.
24 */
25 MED::MED(driverTypes driverType, const string & fileName)
26 {
27   const char * LOC = "MED::MED(driverTypes driverType, const string & fileName) : ";
28   BEGIN_OF(LOC);
29
30   MESSAGE(LOC << "driverType = " << driverType);
31
32   MED_MED_RDONLY_DRIVER * myDriver = new MED_MED_RDONLY_DRIVER(fileName,this) ;
33   int current = addDriver(*myDriver);
34   //int current= addDriver(driverType,fileName);
35
36   _drivers[current]->open();
37   _drivers[current]->readFileStruct();
38   _drivers[current]->close();
39
40   END_OF(LOC);
41 };
42
43 /*!
44   Destructor.
45 */
46 MED::~MED()
47 {
48   const char * LOC = "MED::~MED() : ";
49   BEGIN_OF(LOC);
50
51   // Analysis of the object MED
52
53   int index;
54
55   map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
56   index = 0;
57   for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
58     if ( (*currentField).first != NULL) index++;
59   }
60
61   MESSAGE(LOC << " there is(are) " << index << " field(s):");
62   for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
63     if ( (*currentField).first != NULL) MESSAGE("             " << ((*currentField).first)->getName().c_str());
64   }
65
66   map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::iterator itSupportOnMesh ;
67   index = 0;
68   for ( itSupportOnMesh=_support.begin();itSupportOnMesh != _support.end(); itSupportOnMesh++ ) {
69     map<MED_FR::med_entite_maillage,SUPPORT *>::iterator itSupport ;
70     for ( itSupport=(*itSupportOnMesh).second.begin();itSupport!=(*itSupportOnMesh).second.end();itSupport++)
71       index++;
72   }
73
74   MESSAGE(LOC << " there is(are) " << index << " support(s):");
75
76   map<MESH_NAME_,MESH*>::const_iterator  currentMesh;
77   index =0;
78   for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
79     if ( (*currentMesh).second != NULL)
80       index++;
81   }
82
83   MESSAGE(LOC << " there is(are) " << index << " meshe(s):");
84 //   for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
85 //     if ( (*currentMesh).second != NULL)
86 //       {
87 //      SCRUTE((*currentMesh).second);
88
89 //      string meshName = ((*currentMesh).second)->getName();
90
91 //      MESSAGE("             " << meshName);
92 //       }
93 //   }
94
95   // delete all ? : PG : YES !
96   //  map<FIELD_ *, MESH_NAME_>::const_iterator currentField;
97   for ( currentField=_meshName.begin();currentField != _meshName.end(); currentField++ ) {
98     if ( (*currentField).first != NULL) {
99       // cast in right type to delete it !
100       switch ((*currentField).first->getValueType()) {
101       case MED_INT32 : 
102         delete (FIELD<int>*) (*currentField).first ;
103         break ;
104       case MED_REEL64 :
105         delete (FIELD<double>*) (*currentField).first ;
106         break ;
107       default : 
108         MESSAGE(LOC << "Field has type different of int or double, could not destroy its values array !") ;
109         delete (*currentField).first;
110       }
111     }
112   }
113   //  map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::iterator itSupportOnMesh ;
114   for ( itSupportOnMesh=_support.begin();itSupportOnMesh != _support.end(); itSupportOnMesh++ ) {
115     map<MED_FR::med_entite_maillage,SUPPORT *>::iterator itSupport ;
116     for ( itSupport=(*itSupportOnMesh).second.begin();itSupport!=(*itSupportOnMesh).second.end();itSupport++)
117         delete (*itSupport).second ;
118   }
119
120   //  map<MESH_NAME_,MESH*>::const_iterator  currentMesh;
121   for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
122     if ( (*currentMesh).second != NULL)
123       {
124         if (!((*currentMesh).second)->getIsAGrid())
125           delete (*currentMesh).second;
126         else
127           delete (GRID *) (*currentMesh).second;
128       }
129   }
130
131   index =_drivers.size();
132
133   MESSAGE(LOC << "In this object MED there is(are) " << index << " driver(s):");
134
135   for (unsigned int ind=0; ind < _drivers.size(); ind++ )
136     {
137       SCRUTE(_drivers[ind]);
138       if ( _drivers[ind] != NULL) delete _drivers[ind];
139     }
140
141
142
143   END_OF(LOC);
144 } ;
145
146 // ------- Drivers Management Part
147
148 // Add your new driver instance declaration here (step 3-1)
149 MED::INSTANCE_DE<MED_MED_RDWR_DRIVER> MED::inst_med ;
150 MED::INSTANCE_DE<VTK_MED_DRIVER> MED::inst_vtk ;
151
152 // Add your new driver instance in the MED instance list (step 3-2)
153 const MED::INSTANCE * const MED::instances[] = { &MED::inst_med, &MED::inst_vtk }; 
154
155 /*!
156   Create the specified driver and return its index reference to path to 
157   read or write methods.
158 */
159 int MED::addDriver(driverTypes driverType, const string & fileName="Default File Name.med") {
160
161   const char * LOC = "MED::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\") : ";
162   GENDRIVER * driver;
163   int current;
164   int itDriver = (int) NO_DRIVER;
165
166   BEGIN_OF(LOC);
167
168   MESSAGE(LOC << " the file name is " << fileName);
169
170   SCRUTE(driverType);
171
172   SCRUTE(instances[driverType]);
173
174   switch(driverType)
175     {
176     case MED_DRIVER : {
177       itDriver = (int) driverType ;
178       break ;
179     }
180
181     case VTK_DRIVER : {
182       itDriver = 1 ;
183       break ;
184     }
185
186     case GIBI_DRIVER : {
187       throw MED_EXCEPTION (LOCALIZED(STRING(LOC)<< "GIBI_DRIVER has been specified to the method which is not allowed because there is no GIBI driver for the MED object"));
188       break;
189     }
190
191     case NO_DRIVER : {
192       throw MED_EXCEPTION (LOCALIZED(STRING(LOC)<< "NO_DRIVER has been specified to the method which is not allowed"));
193       break;
194     }
195     }
196
197   if (itDriver == ((int) NO_DRIVER))
198     throw MED_EXCEPTION (LOCALIZED(STRING(LOC)<< "NO_DRIVER has been specified to the method which is not allowed"));
199
200   driver = instances[itDriver]->run(fileName, this) ;
201
202   current = _drivers.size()-1;
203
204   driver->setId(current); 
205
206   END_OF(LOC);
207
208   return current;
209 }
210
211 /*!
212   Duplicate the given driver and return its index reference to path to 
213   read or write methods.
214 */
215 int  MED::addDriver(GENDRIVER & driver) {
216   const char * LOC = "MED::addDriver(GENDRIVER &) : ";
217   int current;
218
219   BEGIN_OF(LOC);
220   
221   SCRUTE(_drivers.size());
222
223   _drivers.push_back(&driver);
224
225   SCRUTE(_drivers.size());
226
227   SCRUTE(_drivers[0]);
228   SCRUTE(driver);
229
230   current = _drivers.size()-1;
231   driver.setId(current); 
232   
233   END_OF(LOC);
234   return current;
235   
236 }
237
238 /*!
239   Remove the driver referenced by its index.
240 */
241 void MED::rmDriver (int index/*=0*/)
242   throw (MED_EXCEPTION)
243 {
244   const char * LOC = "MED::rmDriver (int index=0): ";
245   BEGIN_OF(LOC);
246
247   if (_drivers[index])
248     //_drivers.erase(&_drivers[index]); 
249     {}
250   else
251     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
252                                      << "The index given is invalid, index must be between 0 and |" 
253                                      << _drivers.size()
254                                      )
255                           );   
256   END_OF(LOC);
257 }
258
259 /*!
260   ??? to do comment ???
261 */
262 void MED::writeFrom (int index/*=0*/)
263   throw (MED_EXCEPTION)
264 {
265   const char * LOC = "MED::write (int index=0): ";
266   BEGIN_OF(LOC);
267
268   if (_drivers[index]) {
269     // open and close are made by all objects !
270     _drivers[index]->writeFrom();
271   }
272   throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
273                                    << "The index given is invalid, index must be between 0 and |" 
274                                    << _drivers.size()
275                                    )
276                         ); 
277   END_OF(LOC);
278 }; 
279
280 /*!
281   Write all objects with the driver given by its index.
282 */
283 void MED::write (int index/*=0*/)
284   throw (MED_EXCEPTION)
285 {
286   const char * LOC = "MED::write (int index=0): ";
287   BEGIN_OF(LOC);
288
289   if (_drivers[index]) {
290     // open and close are made by the subsequent objects !
291     _drivers[index]->write(); 
292   }
293   else
294     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
295                                      << "The index given is invalid, index must be between  0 and |" 
296                                      << _drivers.size()
297                                      )
298                           ); 
299   END_OF(LOC);
300 }; 
301
302 /*!
303   Parse all the file and generate empty object.
304
305   All object must be read explicitly later with their own method read 
306   or use MED::read to read all.
307
308   This method is automaticaly call by constructor with driver information.
309 */
310 void MED::readFileStruct (int index/*=0*/)
311   throw (MED_EXCEPTION)
312 {
313   const char * LOC = "MED::readFileStruct (int index=0): ";
314   BEGIN_OF(LOC);
315   
316   if (_drivers[index]) {
317     _drivers[index]->open(); 
318     _drivers[index]->readFileStruct(); 
319     _drivers[index]->close(); 
320   }
321   else
322     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
323                                      << "The index given is invalid, index must be between 0 and |" 
324                                      << _drivers.size()
325                                      )
326                           );   
327   END_OF(LOC);
328 }
329
330 /*!
331   Read all objects in the file specified in the driver given by its index.
332 */
333 void MED::read  (int index/*=0*/)
334   throw (MED_EXCEPTION)
335 {
336   const char * LOC = "MED::read (int index=0): ";
337   BEGIN_OF(LOC);
338   
339   if (_drivers[index]) {
340     // open and close are made by all objects !
341     SCRUTE(index);
342     SCRUTE(_drivers[index]);
343     SCRUTE(&_drivers[index]);
344     //    _drivers[index]->open();
345     _drivers[index]->read();
346     //    _drivers[index]->close();
347   }
348   else
349     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
350                                      << "The index given is invalid, index must be between  >0 and < |" 
351                                      << _drivers.size()-1 
352                                      )
353                           );  
354   END_OF(LOC);
355   
356 };
357
358 // ------- End Of Drivers Management Part
359
360 /*!
361   Get the number of MESH objects.
362 */
363 int      MED::getNumberOfMeshes ( void ) const {
364
365   const char * LOC = "MED::getNumberOfMeshes ( void ) const : ";
366   BEGIN_OF(LOC);
367
368   return _meshes.size();
369
370   END_OF(LOC);
371 };   
372     
373 /*!
374   Get the number of FIELD objects.
375 */
376 int      MED::getNumberOfFields ( void ) const {
377
378   const char * LOC = "MED::getNumberOfFields ( void ) const : ";
379   BEGIN_OF(LOC);
380
381   return _fields.size(); // we get number of field with different name
382
383   END_OF(LOC);
384 };       
385
386 /*!
387   Get the names of all MESH objects.
388
389   meshNames is an in/out argument.
390
391   It is a string array of size the
392   number of MESH objects. It must be allocated before calling
393   this method. All names are put in it.
394 */
395 void MED::getMeshNames      ( string * meshNames ) const
396   throw (MED_EXCEPTION)
397 {
398   const char * LOC = "MED::getMeshNames ( string * ) const : ";
399   BEGIN_OF(LOC);
400   unsigned int meshNamesSize;
401   
402   if (  ( meshNamesSize = sizeof(meshNames) / sizeof(string *) )
403        != _meshes.size() )
404     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
405                                      << "Size of parameter meshNames is |" 
406                                      << meshNamesSize    << "| and should be |" 
407                                      << _meshes.size() << "| and should be |" 
408                                      )
409                           );   
410   
411   // REM : ALLOCATION D'UN TABLEAU DE POINTEURS SUR STRING FAITE PAR LE CLIENT
412   map<MESH_NAME_,MESH*>::const_iterator  currentMesh; // ??ITERATEUR CONST SUR UN OBJET NON CONST ??
413
414   int meshNamesIndex = 0;
415
416   for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
417     meshNames[meshNamesIndex]=(*currentMesh).first;
418     meshNamesIndex++;                               // CF OPTIMISATION
419   }
420
421   END_OF(LOC);
422 };
423
424 /*!
425   Get the names of all MESH objects.
426
427   Return a deque<string> object which contain the name of all MESH objects.
428 */
429 deque<string> MED::getMeshNames      () const {
430   
431   const char * LOC = "MED::getMeshNames () const : ";
432   BEGIN_OF(LOC);
433
434   deque<string> meshNames(_meshes.size());
435   
436   map<MESH_NAME_,MESH*>::const_iterator  currentMesh; // ??ITERATEUR CONST SUR UN OBJET NON CONST ??
437
438   int meshNamesIndex = 0;
439
440   for ( currentMesh=_meshes.begin();currentMesh != _meshes.end(); currentMesh++ ) {
441     meshNames[meshNamesIndex]=(*currentMesh).first;
442     meshNamesIndex++;                               // CF OPTIMISATION
443   }
444
445   END_OF(LOC);
446   return meshNames ;
447 };
448
449
450 /*!
451   Return a reference to the MESH object named meshName.
452 */
453 MESH   * MED::getMesh           ( const string & meshName )  const
454   throw (MED_EXCEPTION)
455 {
456
457   const char * LOC = "MED::getMesh ( const string & meshName ) const : ";
458   BEGIN_OF(LOC);
459
460   map<MESH_NAME_,MESH*>::const_iterator itMeshes =  _meshes.find(meshName);
461
462   if ( itMeshes == _meshes.end() )
463     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
464                                      << "There is no known mesh named |" 
465                                      << meshName << "|"
466                                      )
467                           );
468   
469   return (*itMeshes).second;
470   
471   END_OF(LOC);
472 }
473
474 /*!
475  \internal Return a reference to the MESH object associated with 
476  field argument.
477 */
478 MESH   * MED::getMesh           (const FIELD_ * const field ) const
479   throw (MED_EXCEPTION)
480 {
481  
482   const char * LOC = "MED::getMesh ( const FIELD * field ) const : ";
483   BEGIN_OF(LOC);
484
485   FIELD_ * f = const_cast< FIELD_* > (field);     //  Comment faire mieux ?
486   map<FIELD_ *, MESH_NAME_>::const_iterator itMeshName = _meshName.find(f);
487
488   if ( itMeshName  == _meshName.end() )
489     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
490                                      << "There is no known mesh associated with |" 
491                                      << field << "| pointer"
492                                      )
493                           );   
494   
495   string meshName = (*itMeshName).second;
496   map<MESH_NAME_,MESH*>::const_iterator itMeshes =  _meshes.find(meshName);
497   if ( itMeshes == _meshes.end() )
498     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
499                                      << "There is no known mesh named |"
500                                      << meshName << " while it's associated with the found field |" 
501                                      << field << "| pointer"
502                                      )
503                           );   
504   
505   return (*itMeshes).second;
506   
507   END_OF(LOC);
508 };
509
510
511 /*!
512   Get the names of all FIELD objects.
513
514   fieldNames is an in/out argument.
515
516   It is an array of string of size the
517   number of FIELD objects. It must be allocated before calling
518   this method. All names are put in it.
519 */
520 void MED::getFieldNames     ( string * fieldNames ) const
521   throw (MED_EXCEPTION)
522 {
523   const char * LOC = "MED::getFieldNames ( string * ) const : ";
524   BEGIN_OF(LOC);
525
526   unsigned int fieldNamesSize =  sizeof(fieldNames) / sizeof(string *);
527  
528   if ( fieldNamesSize != _fields.size() )
529     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
530                                      << "Size of parameter fieldNames is |" 
531                                      << fieldNamesSize     << "| and should be |" 
532                                      << _fields.size() << "| and should be |" 
533                                      )
534                           );   
535   
536   // REM : ALLOCATION D'UN TABLEAU DE POINTEURS SUR STRING FAITE PAR LE CLIENT
537   map<FIELD_NAME_,MAP_DT_IT_>::const_iterator  currentField;
538
539   int fieldNamesIndex = 0;
540   for ( currentField=_fields.begin();currentField != _fields.end(); currentField++ ) {
541     fieldNames[fieldNamesIndex]=(*currentField).first;
542     fieldNamesIndex++;                               // CF OPTIMISATION
543   }
544
545   END_OF(LOC);
546
547 };
548
549 /*!
550   Get the names of all FIELD objects.
551
552   Return a deque<string> object which contain the name of all FIELD objects.
553 */
554 deque<string> MED::getFieldNames     () const {
555
556   const char * LOC = "MED::getFieldNames ( ) const : ";
557   BEGIN_OF(LOC);
558
559   deque<string> fieldNames(_fields.size());
560
561   map<FIELD_NAME_,MAP_DT_IT_>::const_iterator  currentField;
562
563   int fieldNamesIndex = 0;
564
565   for ( currentField=_fields.begin();currentField != _fields.end(); currentField++ ) {
566     fieldNames[fieldNamesIndex]=(*currentField).first;
567     fieldNamesIndex++;                               // CF OPTIMISATION
568   }
569
570   END_OF(LOC);
571   return fieldNames ;
572 };
573
574 /*!
575   Return a deque<DT_IT_> which contain all iteration step for the FIELD 
576   identified by its name.
577 */
578 deque<DT_IT_> MED::getFieldIteration (const string & fieldName) const
579   throw (MED_EXCEPTION)
580 {
581
582   const char * LOC = "MED::getFieldIteration ( const string & ) const : ";
583   BEGIN_OF(LOC);
584
585   map<FIELD_NAME_,MAP_DT_IT_>::const_iterator itFields = _fields.find(fieldName);
586   
587   if ( itFields == _fields.end() ) 
588     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
589                                      << "There is no known field named |" 
590                                      << fieldName << "|"
591                                      )
592                           );   
593   //  const MAP_DT_IT_ & myIterationMap =  const_cast<const MAP_DT_IT_ & > ((*itFields).second);
594   const MAP_DT_IT_ & myIterationMap =  (*itFields).second ;
595   MAP_DT_IT_::const_iterator currentIterator ;
596   
597   deque<DT_IT_> Iteration(myIterationMap.size());
598   
599   int iterationIndex = 0;
600   
601   for ( currentIterator=myIterationMap.begin();currentIterator != myIterationMap.end(); currentIterator++ ) {
602     Iteration[iterationIndex]=(*currentIterator).first;
603     iterationIndex++;                               // CF OPTIMISATION
604   }
605
606   END_OF(LOC);
607   return Iteration ;
608 };
609
610 /*!
611  Return a reference to the FIELD object named fieldName with 
612  time step number dt and order number it.
613 */
614 FIELD_  * MED::getField          ( const string & fieldName, const int dt=MED_NOPDT, const int it=MED_NOPDT ) const
615   throw (MED_EXCEPTION)
616 {
617
618   const char * LOC = "MED::getField ( const string &, const int, const int ) const : ";
619   BEGIN_OF(LOC);
620
621   MESSAGE(LOC << "fieldName = "<<fieldName<<", dt ="<<dt<<", it = "<<it);
622
623   DT_IT_ dtIt;
624
625   dtIt.dt= dt;
626   dtIt.it= it;
627
628   map<FIELD_NAME_,MAP_DT_IT_>::const_iterator itFields = _fields.find(fieldName);
629
630   if ( itFields == _fields.end() ) 
631     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
632                                      << "There is no known field named |" 
633                                      << fieldName << "|"
634                                      )
635                           );   
636
637   const MAP_DT_IT_ & map_dtIt =  const_cast<const MAP_DT_IT_ & > ((*itFields).second);
638   MAP_DT_IT_::const_iterator itMap_dtIt =  map_dtIt.find(dtIt);
639
640   if ( itMap_dtIt == map_dtIt.end() )
641     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
642                                      << "There is no (dt,it) |("
643                                      << dt << "," << it << ")| associated with the found field |" 
644                                      << fieldName << "|"
645                                      )
646                           );   
647
648   END_OF(LOC);
649
650   //return _fields[fieldName][dtIt];
651   return (*itMap_dtIt).second;
652   
653 };
654
655
656 // fiend ostream & MED::operator<<(ostream &os,const MED & med) const {
657 //   return os;
658 // };
659
660 /*!
661   Return a map<MED_FR::med_entite_maillage,SUPPORT*> which contain 
662   foreach entity, a reference to the SUPPORT on all elements.
663 */
664 const map<MED_FR::med_entite_maillage,SUPPORT*> & MED::getSupports(const string & meshName) const
665   throw (MED_EXCEPTION)
666 {
667   const char * LOC = "MED::getSupports ( const string ) const : ";
668   BEGIN_OF(LOC);
669
670   map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::const_iterator itSupportOnMesh = _support.find(meshName) ;
671   
672   if ( itSupportOnMesh == _support.end() )
673     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
674                                      << "There is no support on mesh named |" 
675                                      << meshName << "|"
676                                      )
677                           );
678   END_OF(LOC);
679   return (*itSupportOnMesh).second ;
680 }
681
682 /*!
683   Return a reference to the SUPPORT object on all elements of entity 
684   for the MESH named meshName.
685 */
686 SUPPORT *  MED::getSupport (const string & meshName,MED_FR::med_entite_maillage entity) const 
687   throw (MED_EXCEPTION)
688 {
689   const char * LOC = "MED::getSupport ( const string, MED_FR::med_entite_maillage ) const : ";
690   BEGIN_OF(LOC);
691
692   int index = 0;
693   for (map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::const_iterator const_itSupportOnMesh=_support.begin(); const_itSupportOnMesh != _support.end();
694        const_itSupportOnMesh++ )
695     {
696       map<MED_FR::med_entite_maillage,SUPPORT *>::const_iterator const_itSupport ;
697       for (const_itSupport=(*const_itSupportOnMesh).second.begin();
698            const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++) index++;
699     }
700
701   MESSAGE(LOC << "In this MED object there is(are) " << index << " support(s):");
702
703   for (map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::const_iterator const_itSupportOnMesh=_support.begin();const_itSupportOnMesh != _support.end(); const_itSupportOnMesh++ )
704     {
705       map<MED_FR::med_entite_maillage,SUPPORT *>::const_iterator const_itSupport ;
706       for (const_itSupport=(*const_itSupportOnMesh).second.begin();
707            const_itSupport!=(*const_itSupportOnMesh).second.end();const_itSupport++)
708         {
709           MESSAGE(LOC << "Support on mesh " << (*const_itSupportOnMesh).first << " on entity " << (*const_itSupport).first << " : " << *((*const_itSupport).second));
710         }
711   }
712
713
714   map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::const_iterator const_itSupportOnMesh = _support.find(meshName) ;
715   
716   if ( const_itSupportOnMesh == _support.end() )
717     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
718                                      << "There is no support on mesh named |" 
719                                      << meshName << "|"
720                                      )
721                           );
722  
723 //   map<MED_FR::med_entite_maillage,SUPPORT *> & SupportOnMesh = (map<MED_FR::med_entite_maillage,SUPPORT *>&) ((*itSupportOnMesh).second) ;
724 //   map<MED_FR::med_entite_maillage,SUPPORT *>::const_iterator itSupport = SupportOnMesh.find(entity) ;
725   
726 //   if (itSupport == SupportOnMesh.end() )
727 //     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
728 //                                      << "There is no support on entity "
729 //                                   << entity << " in mesh named |" 
730 //                                      << meshName << "|"
731 //                                      )
732 //                           );
733
734
735   map<MED_FR::med_entite_maillage,SUPPORT *> SupportOnMesh = ((*const_itSupportOnMesh).second);
736
737   map<MED_FR::med_entite_maillage,SUPPORT *>::const_iterator itSupport = SupportOnMesh.find(entity) ;
738   
739   if (itSupport == SupportOnMesh.end() )
740     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
741                                      << "There is no support on entity "
742                                      << entity << " in mesh named |" 
743                                      << meshName << "|"
744                                      )
745                           );
746   END_OF(LOC);
747   return (*itSupport).second ;
748 };
749
750 /*!
751   Temporary method : when all MESH objects are read, this methods 
752   update all SUPPORT objects with the rigth dimension.
753 */
754 void MED::updateSupport ()
755 {
756  
757   const char * LOC = "MED::updateSupport () : ";
758   BEGIN_OF(LOC);
759
760   map<MESH_NAME_, map<MED_FR::med_entite_maillage,SUPPORT *> >::iterator itSupportOnMesh ;
761   for ( itSupportOnMesh=_support.begin();itSupportOnMesh != _support.end(); itSupportOnMesh++ ) {
762     map<MED_FR::med_entite_maillage,SUPPORT *>::iterator itSupport ;
763     for ( itSupport=(*itSupportOnMesh).second.begin();itSupport!=(*itSupportOnMesh).second.end();itSupport++)
764       try {
765         (*itSupport).second->update() ;
766       }
767       catch (MEDEXCEPTION & ex) {
768         // entity not defined in mesh -> we remove support on it !
769         MESSAGE(LOC<<ex.what());
770         delete (*itSupport).second ;
771         (*itSupportOnMesh).second.erase(itSupport) ; // that's rigth ????
772         itSupport-- ;
773       }
774   }
775
776   END_OF(LOC);
777 }
778
779 /*!
780   Add the given MESH object. MED object control it,
781   and destroy it, so you must not destroy it after.
782
783   The meshName is given by the MESH object.
784 */
785 void MED::addMesh( MESH * const ptrMesh)
786   throw (MED_EXCEPTION)
787 {
788   const char * LOC = "MED::addMesh(const MESH * ptrMesh): ";
789   BEGIN_OF(LOC);
790
791   if ( ! ptrMesh ) 
792     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrMesh must not be NULL !"));
793  
794   string meshName;
795   if ( ! ( meshName = ptrMesh->getName()).size() ) 
796     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrMesh->_name must not be NULL !"));
797
798 //   MESH * meshToMed = new MESH(*ptrMesh); DO WE HAVE TO COPY THE ENTRY MESH OR NOT ????? (NB)
799
800   _meshes[meshName] = ptrMesh; // if ptrMesh->meshName already exists it is modified
801
802 //   _meshes[meshName] = meshToMed;
803
804   END_OF(LOC);
805 }
806
807 /*!
808   Add the given FIELD object. MED object control it,
809   and destroy it, so you must not destroy it after.
810
811   The fieldName is given by the FIELD object.
812 */
813 void MED::addField( FIELD_ * const ptrField)
814   throw (MED_EXCEPTION)
815 {
816   const char * LOC = "MED::addField(const FIELD_ * const ptrField): ";
817   BEGIN_OF(LOC);
818   
819   if ( ! ptrField ) 
820     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrField must not be NULL !"));
821
822   string fieldName;
823   if ( ! (fieldName = ptrField->getName()).size() ) 
824     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrField->_name must not be NULL !"));
825   
826   SUPPORT * ptrSupport;
827   if ( ! ( ptrSupport = (SUPPORT * ) ptrField->getSupport()) ) 
828     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrField->_support must not be NULL !"));
829   
830   MESH * ptrMesh;
831   if ( ! ( ptrMesh = ptrSupport->getMesh()) ) 
832     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrField->_support->_mesh must not be NULL !"));
833
834   string meshName;
835   if ( ! ( meshName = ptrMesh->getName()).size() ) 
836     throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "ptrField->_support->_mesh->_name must not be NULL !"));
837
838   DT_IT_ dtIt;
839   dtIt.dt  = ptrField->getIterationNumber();
840   dtIt.it  = ptrField->getOrderNumber();
841                 
842   _fields   [fieldName][dtIt] = ptrField; // if it already exists it is replaced
843   _meshName [ptrField]        = meshName; // if it already exists it is replaced
844   _meshes   [meshName]        = ptrMesh;  // if it already exists it is replaced
845
846   //  int  numberOfTypes = ptrSupport->getNumberOfTypes(); !! UNUSED VARIABLE !!
847   _support  [meshName][ (MED_FR::med_entite_maillage) ptrSupport->getEntity()] = ptrSupport;// if it already exists it is replaced
848
849
850   END_OF(LOC);
851 }