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