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