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