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