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