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