Salome HOME
0021803: EDF 2351 : Available versions of MED in TUI function ExportMED aren't consis...
[modules/smesh.git] / src / MEDWrapper / MED_V2_2_Wrapper.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "MED_V2_2_Wrapper.hxx"
24 #include "MED_Algorithm.hxx"
25 #include "MED_Utilities.hxx"
26
27 #include <med.h>
28 #include <med_err.h>
29
30 #ifdef _DEBUG_
31 static int MYDEBUG = 0;
32 // #else
33 // static int MYDEBUG = 0;
34 #endif
35
36 namespace MED
37 {
38   TInt
39   GetDESCLength()
40   {
41     return 200;
42   }
43
44   TInt
45   GetIDENTLength()
46   {
47     return 8;
48   }
49
50   TInt
51   GetNOMLength()
52   {
53     return 64;
54   }
55
56   TInt
57   GetLNOMLength()
58   {
59     return 80;
60   }
61
62   TInt
63   GetPNOMLength()
64   {
65     return 16;
66   }
67
68   void
69   GetVersionRelease(TInt& majeur, TInt& mineur, TInt& release)
70   {
71     majeur=MED_MAJOR_NUM;
72     mineur=MED_MINOR_NUM;
73     release=MED_RELEASE_NUM;
74   }
75
76   TInt
77   GetNbConn(EGeometrieElement typmai,
78                    EEntiteMaillage typent,
79                    TInt mdim)
80   {
81     return typmai%100;
82   }
83
84   namespace V2_2
85   {
86     //---------------------------------------------------------------
87     class TFile{
88       TFile();
89       TFile(const TFile&);
90       
91     public:
92       TFile(const std::string& theFileName): 
93         myCount(0),
94         myFid(0), 
95         myFileName(theFileName)
96       {}
97       
98       ~TFile()
99       { 
100         Close();
101       }
102       
103       void
104       Open(EModeAcces theMode, TErr* theErr = NULL)
105       {
106         if(myCount++ == 0){
107           const char* aFileName = myFileName.c_str();
108           myFid = MEDfileOpen(aFileName,med_access_mode(theMode));
109         }
110         if(theErr)
111           *theErr = TErr(myFid);
112         else if(myFid < 0)
113           EXCEPTION(std::runtime_error,"TFile - MEDfileOpen('"<<myFileName<<"',"<<theMode<<")");
114       }
115
116       const TIdt& Id() const 
117       { 
118         if(myFid < 0)
119           EXCEPTION(std::runtime_error,"TFile - GetFid() < 0");
120         return myFid;
121       }
122
123       void Close()
124       { 
125         if(--myCount == 0)
126           MEDfileClose(myFid);
127       }
128
129     protected:
130       TInt myCount;
131       TIdt myFid;
132       std::string myFileName;
133     };
134
135     //---------------------------------------------------------------
136     class TFileWrapper
137     {
138       PFile myFile;
139
140     public:
141       TFileWrapper(const PFile& theFile, EModeAcces theMode, TErr* theErr = NULL): 
142         myFile(theFile)
143       {
144         myFile->Open(theMode,theErr);
145       }
146       
147       ~TFileWrapper()
148       {
149         myFile->Close();
150       }
151     };
152
153     //---------------------------------------------------------------
154     TVWrapper::TVWrapper(const std::string& theFileName):
155       myFile(new TFile(theFileName))
156     {
157       TErr aRet;
158       myFile->Open( eLECTURE_ECRITURE, &aRet );
159       // if(aRet < 0)
160       //   myFile->Close();
161       //   myFile->Open( eLECTURE_AJOUT, &aRet );
162       // }
163       if(aRet < 0) {
164         myFile->Close();
165         myFile->Open( eLECTURE, &aRet );
166       }
167       if(aRet < 0) {
168         myFile->Close();
169         myFile->Open( eCREATION, &aRet );
170       }
171     }
172
173     //----------------------------------------------------------------------------
174     TInt
175     TVWrapper
176     ::GetNbMeshes(TErr* theErr)
177     {
178       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
179       
180       if(theErr && *theErr < 0)
181         return -1;
182       
183       return MEDnMesh(myFile->Id());
184     }
185     
186     //----------------------------------------------------------------------------
187     void
188     TVWrapper
189     ::GetMeshInfo(TInt theMeshId, 
190                   MED::TMeshInfo& theInfo,
191                   TErr* theErr)
192     {
193       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
194       
195       if(theErr && *theErr < 0)
196         return;
197       
198       TValueHolder<TString, char> aMeshName(theInfo.myName);
199       TValueHolder<TInt, med_int> aDim(theInfo.myDim);
200       TValueHolder<TInt, med_int> aSpaceDim(theInfo.mySpaceDim);
201       TValueHolder<EMaillage, med_mesh_type> aType(theInfo.myType);
202       char dtunit[MED_SNAME_SIZE+1];
203       med_sorting_type sorttype;
204       med_int nstep;
205       med_axis_type at;
206       int naxis=MEDmeshnAxis(myFile->Id(),theMeshId);
207       char *axisname=new char[naxis*MED_SNAME_SIZE+1];
208       char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
209       TErr aRet = MEDmeshInfo(myFile->Id(),
210                               theMeshId,
211                               &aMeshName,
212                               &aSpaceDim,
213                               &aDim,
214                               &aType,
215                               &theInfo.myDesc[0],
216                               dtunit,
217                               &sorttype,
218                               &nstep,
219                               &at,
220                               axisname,
221                               axisunit);
222       delete [] axisname;
223       delete [] axisunit;
224       if(aRet < 0)
225         EXCEPTION(std::runtime_error,"GetMeshInfo - MEDmeshInfo(...)");
226     }
227     
228     //----------------------------------------------------------------------------
229     void
230     TVWrapper
231     ::SetMeshInfo(const MED::TMeshInfo& theInfo,
232                   EModeAcces theMode,
233                   TErr* theErr)
234     {
235       TFileWrapper aFileWrapper(myFile,theMode,theErr);
236       
237       if(theErr && *theErr < 0)
238         return;
239       
240       MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
241       
242       TValueHolder<TString, char> aMeshName(anInfo.myName);
243       TValueHolder<TInt, med_int> aDim(anInfo.myDim);
244       TValueHolder<TInt, med_int> aSpaceDim(anInfo.mySpaceDim);
245       TValueHolder<EMaillage, med_mesh_type> aType(anInfo.myType);
246       TValueHolder<TString, char> aDesc(anInfo.myDesc);
247
248       char *nam=new char[aSpaceDim*MED_SNAME_SIZE+1];
249       std::fill(nam,nam+aSpaceDim*MED_SNAME_SIZE+1,'\0');
250       char *unit=new char[aSpaceDim*MED_SNAME_SIZE+1];
251       std::fill(unit,unit+aSpaceDim*MED_SNAME_SIZE+1,'\0');
252       TErr aRet = MEDmeshCr(myFile->Id(),
253                             &aMeshName,
254                             aSpaceDim,
255                             aDim,
256                             aType,
257                             &aDesc,
258                             "",
259                             MED_SORT_DTIT,
260                             MED_CARTESIAN,
261                             nam,
262                             unit);
263       delete [] nam;
264       delete [] unit;
265       
266       //if(aRet == 0)
267       //  aRet = MEDunvCr(myFile->Id(),&aMeshName);
268       
269       INITMSG(MYDEBUG,"TVWrapper::SetMeshInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
270       
271       if(theErr) 
272         *theErr = aRet;
273       else if(aRet < 0)
274         EXCEPTION(std::runtime_error,"SetMeshInfo - MEDmeshCr(...)");
275     }
276     
277     //----------------------------------------------------------------------------
278     void 
279     TVWrapper
280     ::SetMeshInfo(const MED::TMeshInfo& theInfo,
281                   TErr* theErr)
282     {
283       TErr aRet;
284       SetMeshInfo(theInfo,eLECTURE_ECRITURE,&aRet);
285       
286       if(aRet < 0)
287         SetMeshInfo(theInfo,eLECTURE_AJOUT,&aRet);
288
289       if(aRet < 0)
290         SetMeshInfo(theInfo,eCREATION,&aRet);
291
292       if(theErr)
293         *theErr = aRet;
294     }
295     
296     //----------------------------------------------------------------------------
297     TInt
298     TVWrapper
299     ::GetNbFamilies(const MED::TMeshInfo& theInfo,
300                     TErr* theErr)
301     {
302       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
303       
304       if(theErr && *theErr < 0)
305         return -1;
306       
307       MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
308       TValueHolder<TString, char> aName(anInfo.myName);
309       return MEDnFamily(myFile->Id(),&aName);
310     }
311     
312     //----------------------------------------------------------------------------
313     TInt
314     TVWrapper
315     ::GetNbFamAttr(TInt theFamId, 
316                    const MED::TMeshInfo& theInfo,
317                    TErr* theErr)
318     {
319       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
320       
321       if(theErr && *theErr < 0)
322         return -1;
323       
324       MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
325
326       TValueHolder<TString, char> aName(anInfo.myName);
327
328       return MEDnFamily23Attribute(myFile->Id(),&aName,theFamId);
329     }
330     
331     //----------------------------------------------------------------------------
332     TInt
333     TVWrapper
334     ::GetNbFamGroup(TInt theFamId, 
335                     const MED::TMeshInfo& theInfo,
336                     TErr* theErr)
337     {
338       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
339       
340       if(theErr && *theErr < 0)
341         return -1;
342       
343       MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
344
345       TValueHolder<TString, char> aName(anInfo.myName);
346
347       return MEDnFamilyGroup(myFile->Id(),&aName,theFamId);
348     }
349     
350     //----------------------------------------------------------------------------
351     void
352     TVWrapper
353     ::GetFamilyInfo(TInt theFamId, 
354                     MED::TFamilyInfo& theInfo,
355                     TErr* theErr)
356     {
357       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
358       
359       if(theErr && *theErr < 0)
360         return;
361       
362       MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
363       
364       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
365       TValueHolder<TString, char> aFamilyName(theInfo.myName);
366       TValueHolder<TInt, med_int> aFamilyId(theInfo.myId);
367       TValueHolder<TFamAttr, med_int> anAttrId(theInfo.myAttrId);
368       TValueHolder<TFamAttr, med_int> anAttrVal(theInfo.myAttrVal);
369       TValueHolder<TString, char> anAttrDesc(theInfo.myAttrDesc);
370       TValueHolder<TString, char> aGroupNames(theInfo.myGroupNames);
371       
372       TErr aRet = MEDfamily23Info(myFile->Id(),
373                                   &aMeshName,
374                                   theFamId,
375                                   &aFamilyName,
376                                   &anAttrId,
377                                   &anAttrVal,
378                                   &anAttrDesc,
379                                   &aFamilyId,
380                                   &aGroupNames);
381
382       if(theErr) 
383         *theErr = aRet;
384       else if(aRet < 0)
385         EXCEPTION(std::runtime_error,"GetFamilyInfo - MEDfamily23Info(...) - "<<
386                   " aMeshInfo.myName = '"<<&aMeshName<<
387                   "'; theFamId = "<<theFamId<<
388                   "; theInfo.myNbGroup = "<<theInfo.myNbGroup<<
389                   "; theInfo.myNbAttr = "<<theInfo.myNbAttr);
390     }
391     
392     //----------------------------------------------------------------------------
393     void
394     TVWrapper
395     ::SetFamilyInfo(const MED::TFamilyInfo& theInfo,
396                     EModeAcces theMode,
397                     TErr* theErr)
398     {
399       TFileWrapper aFileWrapper(myFile,theMode,theErr);
400       
401       if(theErr && *theErr < 0)
402         return;
403       
404       MED::TFamilyInfo& anInfo = const_cast<MED::TFamilyInfo&>(theInfo);
405       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
406       
407       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
408       TValueHolder<TString, char> aFamilyName(anInfo.myName);
409       TValueHolder<TInt, med_int> aFamilyId(anInfo.myId);
410       TValueHolder<TFamAttr, med_int> anAttrId(anInfo.myAttrId);
411       TValueHolder<TFamAttr, med_int> anAttrVal(anInfo.myAttrVal);
412       TValueHolder<TInt, med_int> aNbAttr(anInfo.myNbAttr);
413       TValueHolder<TString, char> anAttrDesc(anInfo.myAttrDesc);
414       TValueHolder<TInt, med_int> aNbGroup(anInfo.myNbGroup);
415       TValueHolder<TString, char> aGroupNames(anInfo.myGroupNames);
416
417       TErr aRet = MEDfamilyCr(myFile->Id(),
418                               &aMeshName, 
419                               &aFamilyName,
420                               aFamilyId,
421                               aNbGroup,
422                               &aGroupNames);                 
423
424       INITMSG(MYDEBUG,"TVWrapper::SetFamilyInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
425       
426       if(theErr) 
427         *theErr = aRet;
428       else if(aRet < 0)
429         EXCEPTION(std::runtime_error,"SetFamilyInfo - MEDfamilyCr(...)");
430     }
431     
432     //----------------------------------------------------------------------------
433     void
434     TVWrapper
435     ::SetFamilyInfo(const MED::TFamilyInfo& theInfo,
436                     TErr* theErr)
437     {
438       TErr aRet;
439       SetFamilyInfo(theInfo,eLECTURE_ECRITURE,&aRet);
440       
441       if(aRet < 0)
442         SetFamilyInfo(theInfo,eLECTURE_AJOUT,&aRet);
443
444       if(theErr)
445         *theErr = aRet;
446     }
447     
448     //----------------------------------------------------------------------------
449     void
450     TVWrapper
451     ::GetNames(TElemInfo&        theInfo,
452                TInt              theNb,
453                EEntiteMaillage   theEntity, 
454                EGeometrieElement theGeom,
455                TErr*             theErr)
456     {
457       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
458       
459       if(theErr && *theErr < 0)
460         return;
461       
462       if ( theGeom == eBALL )
463         theGeom = GetBallGeom( theInfo.myMeshInfo );
464
465       MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
466
467       TValueHolder<TString, char>                        aMeshName  (aMeshInfo.myName);
468       TValueHolder<TString, char>                        anElemNames(theInfo.myElemNames);
469       TValueHolder<EEntiteMaillage, med_entity_type>     anEntity   (theEntity);
470       TValueHolder<EGeometrieElement, med_geometry_type> aGeom      (theGeom);
471       
472       TErr aRet = MEDmeshEntityNameRd(myFile->Id(),
473                                       &aMeshName,
474                                       MED_NO_DT,
475                                       MED_NO_IT,
476                                       anEntity,
477                                       aGeom,
478                                       &anElemNames);
479
480       theInfo.myIsElemNames = aRet != 0? eFAUX : eVRAI ;
481
482       if(theErr)
483         *theErr = aRet;
484     }
485
486     //----------------------------------------------------------------------------
487     void
488     TVWrapper
489     ::GetNumeration(TElemInfo&        theInfo,
490                     TInt              theNb,
491                     EEntiteMaillage   theEntity, 
492                     EGeometrieElement theGeom,
493                     TErr*             theErr)
494     {
495       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
496       
497       if(theErr && *theErr < 0)
498         return;
499       
500       if ( theGeom == eBALL )
501         theGeom = GetBallGeom( theInfo.myMeshInfo );
502
503       MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
504       
505       TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
506       TValueHolder<TElemNum, med_int>                    anElemNum(theInfo.myElemNum);
507       TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
508       TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
509       
510       TErr aRet = MEDmeshEntityNumberRd(myFile->Id(),
511                                         &aMeshName,
512                                         MED_NO_DT,
513                                         MED_NO_IT,
514                                         anEntity,
515                                         aGeom,
516                                         &anElemNum);
517
518       theInfo.myIsElemNum = aRet != 0? eFAUX : eVRAI;
519
520       if(theErr)
521         *theErr = aRet;
522     }
523
524     //----------------------------------------------------------------------------
525     void
526     TVWrapper
527     ::GetFamilies(TElemInfo&        theInfo,
528                   TInt              theNb,
529                   EEntiteMaillage   theEntity, 
530                   EGeometrieElement theGeom,
531                   TErr*             theErr)
532     {
533       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
534       
535       if(theErr && *theErr < 0)
536         return;
537
538       if ( theGeom == eBALL )
539         theGeom = GetBallGeom( theInfo.myMeshInfo );
540       
541       MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
542
543       TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
544       TValueHolder<TElemNum, med_int>                    aFamNum  (theInfo.myFamNum);
545       TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
546       TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
547       
548       TErr aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
549                                               &aMeshName,
550                                               MED_NO_DT,
551                                               MED_NO_IT,
552                                               anEntity,
553                                               aGeom,
554                                               &aFamNum);
555
556       if(aRet < 0)
557       {
558 //        if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
559           {
560             int aSize = (int)theInfo.myFamNum->size();
561             theInfo.myFamNum->clear();
562             theInfo.myFamNum->resize(aSize,0);
563             aRet = 0;
564           }
565 //        else
566 //          EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...) of CELLS");
567       }
568       if(theErr)
569         *theErr = aRet;
570     }
571
572     //----------------------------------------------------------------------------
573     void
574     TVWrapper
575     ::SetNames(const TElemInfo& theInfo,
576                EEntiteMaillage theEntity, 
577                EGeometrieElement theGeom,
578                TErr* theErr)
579     { 
580       SetNames(theInfo,eLECTURE_ECRITURE,theEntity,theGeom,theErr);
581     }
582
583     //----------------------------------------------------------------------------
584     void
585     TVWrapper
586     ::SetNames(const TElemInfo&  theInfo,
587                EModeAcces        theMode,
588                EEntiteMaillage   theEntity, 
589                EGeometrieElement theGeom,
590                TErr*             theErr)
591     {
592       TFileWrapper aFileWrapper(myFile,theMode,theErr);
593       
594       if(theErr && *theErr < 0)
595         return;
596
597       if ( theGeom == eBALL )
598         theGeom = GetBallGeom( theInfo.myMeshInfo );
599
600       MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
601       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
602
603       TErr aRet = 0;
604       if(theInfo.myIsElemNames)
605       {
606         TValueHolder<TString, char>                        aMeshName  (aMeshInfo.myName);
607         TValueHolder<TString, char>                        anElemNames(anInfo.myElemNames);
608         TValueHolder<EEntiteMaillage, med_entity_type>     anEntity   (theEntity);
609         TValueHolder<EGeometrieElement, med_geometry_type> aGeom      (theGeom);
610       
611         aRet  = MEDmeshEntityNameWr(myFile->Id(),
612                                     &aMeshName,
613                                     MED_NO_DT,
614                                     MED_NO_IT,
615                                     anEntity,
616                                     aGeom, 
617                                     (TInt)anInfo.myElemNames->size(),
618                                     &anElemNames);
619         if(theErr) 
620           *theErr = aRet;
621         else if(aRet < 0)
622           EXCEPTION(std::runtime_error,"SetNames - MEDmeshEntityNameWr(...)");
623       }
624     }
625
626     //----------------------------------------------------------------------------
627     void
628     TVWrapper
629     ::SetNumeration(const TElemInfo& theInfo,
630                     EEntiteMaillage theEntity, 
631                     EGeometrieElement theGeom,
632                     TErr* theErr)
633     { 
634       SetNumeration(theInfo,eLECTURE_ECRITURE,theEntity,theGeom,theErr);
635     }
636
637     //----------------------------------------------------------------------------
638     void 
639     TVWrapper
640     ::SetNumeration(const TElemInfo&  theInfo,
641                     EModeAcces        theMode,
642                     EEntiteMaillage   theEntity, 
643                     EGeometrieElement theGeom,
644                     TErr*             theErr)
645     {
646       TFileWrapper aFileWrapper(myFile,theMode,theErr);
647       
648       if(theErr && *theErr < 0)
649         return;
650
651       if ( theGeom == eBALL )
652         theGeom = GetBallGeom( theInfo.myMeshInfo );
653
654       MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
655       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
656
657       TErr aRet = 0;
658       if(theInfo.myIsElemNum)
659       {
660         TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
661         TValueHolder<TElemNum, med_int>                    anElemNum(anInfo.myElemNum);
662         TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
663         TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
664       
665         aRet  = MEDmeshEntityNumberWr(myFile->Id(),
666                                       &aMeshName,
667                                       MED_NO_DT,
668                                       MED_NO_IT,
669                                       anEntity,
670                                       aGeom,
671                                       (TInt)anInfo.myElemNum->size(),
672                                       &anElemNum);
673         if(theErr) 
674           *theErr = aRet;
675         else if(aRet < 0)
676           EXCEPTION(std::runtime_error,"SetNumeration - MEDmeshEntityNumberWr(...)");
677       }
678     }
679
680     //----------------------------------------------------------------------------
681     void
682     TVWrapper
683     ::SetFamilies(const TElemInfo&  theInfo,
684                   EEntiteMaillage   theEntity, 
685                   EGeometrieElement theGeom,
686                   TErr*             theErr)
687     { 
688       SetFamilies(theInfo,eLECTURE_ECRITURE,theEntity,theGeom,theErr);
689     }
690
691     //----------------------------------------------------------------------------
692     void 
693     TVWrapper
694     ::SetFamilies(const TElemInfo&  theInfo,
695                   EModeAcces        theMode,
696                   EEntiteMaillage   theEntity, 
697                   EGeometrieElement theGeom,
698                   TErr*             theErr)
699     {
700       TFileWrapper aFileWrapper(myFile,theMode,theErr);
701       
702       if(theErr && *theErr < 0)
703         return;
704
705       if ( theGeom == eBALL )
706         theGeom = GetBallGeom( theInfo.myMeshInfo );
707
708       MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
709       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
710
711       TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
712       TValueHolder<TElemNum, med_int>                    aFamNum  (anInfo.myFamNum);
713       TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
714       TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
715       
716       TErr aRet = MEDmeshEntityFamilyNumberWr(myFile->Id(),
717                                               &aMeshName,
718                                               MED_NO_DT,
719                                               MED_NO_IT,
720                                               anEntity,
721                                               aGeom,
722                                               (TInt)anInfo.myFamNum->size(),
723                                               &aFamNum);
724       
725       if(theErr) 
726         *theErr = aRet;
727       else if(aRet < 0)
728         EXCEPTION(std::runtime_error,"SetFamilies - MEDmeshEntityFamilyNumberWr(...)");
729     }
730     
731     //----------------------------------------------------------------------------
732     TInt
733     TVWrapper
734     ::GetNbNodes(const MED::TMeshInfo& theMeshInfo,
735                  ETable theTable,
736                  TErr* theErr)
737     {
738       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
739       
740       if(theErr && *theErr < 0)
741         return -1;
742       
743       MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
744       
745       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
746       TValueHolder<ETable, med_data_type > aTable(theTable);
747       med_bool chgt,trsf;
748       return MEDmeshnEntity(myFile->Id(),
749                             &aMeshName,
750                             MED_NO_DT,
751                             MED_NO_IT,
752                             MED_NODE,
753                             MED_NO_GEOTYPE,
754                             aTable,
755                             MED_NO_CMODE,
756                             &chgt,
757                             &trsf);
758     }
759     
760     //----------------------------------------------------------------------------
761     void
762     TVWrapper
763     ::GetNodeInfo(MED::TNodeInfo& theInfo,
764                   TErr* theErr)
765     {
766       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
767       
768       if(theErr && *theErr < 0)
769         return;
770       
771       MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
772
773       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
774       TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
775       TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord);
776       TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
777       TValueHolder<ERepere, med_axis_type> aSystem(theInfo.mySystem);
778       TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames);
779       TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits);
780       TValueHolder<TString, char> anElemNames(theInfo.myElemNames);
781       //TValueHolder<EBooleen, med_bool> anIsElemNames(theInfo.myIsElemNames);
782       TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum);
783       //TValueHolder<EBooleen, med_bool> anIsElemNum(theInfo.myIsElemNum);
784       TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
785       TValueHolder<TInt, med_int> aNbElem(theInfo.myNbElem);
786
787       TErr aRet = MEDmeshNodeCoordinateRd(myFile->Id(),
788                                           &aMeshName,
789                                           MED_NO_DT,
790                                           MED_NO_IT,
791                                           aModeSwitch,
792                                           &aCoord);
793
794       TErr aRet2 =MEDmeshEntityFamilyNumberRd(myFile->Id(),
795                                   &aMeshName,
796                                   MED_NO_DT,
797                                   MED_NO_IT,
798                                   MED_NODE,
799                                   MED_NO_GEOTYPE ,
800                                   &aFamNum);
801       if (aRet2  < 0)
802       {
803 //        if (aRet2 == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
804           {
805             int mySize = (int)theInfo.myFamNum->size();
806             theInfo.myFamNum->clear();
807             theInfo.myFamNum->resize(mySize,0);
808           }
809 //        else
810 //          EXCEPTION(std::runtime_error,"GetNodeInfo - MEDmeshEntityFamilyNumberRd(...)");
811       }
812                                   
813       if ( MEDmeshEntityNameRd(myFile->Id(),
814                           &aMeshName,
815                           MED_NO_DT,
816                           MED_NO_IT,
817                           MED_NODE,
818                           MED_NO_GEOTYPE ,
819                           &anElemNames) < 0) theInfo.myIsElemNames=eFAUX;
820       
821       if ( MEDmeshEntityNumberRd(myFile->Id(),
822                             &aMeshName,
823                             MED_NO_DT,
824                             MED_NO_IT,
825                             MED_NODE,
826                             MED_NO_GEOTYPE ,
827                             &anElemNum) < 0 ) theInfo.myIsElemNum=eFAUX;
828       
829       if(theErr) 
830         *theErr = aRet;
831       else if(aRet < 0)
832         EXCEPTION(std::runtime_error,"GetNodeInfo - MEDmeshNodeCoordinateRd(...)");
833     }
834     
835     //----------------------------------------------------------------------------
836     void
837     TVWrapper
838     ::SetNodeInfo(const MED::TNodeInfo& theInfo,
839                   EModeAcces theMode,
840                   TErr* theErr)
841     {
842       TFileWrapper aFileWrapper(myFile,theMode,theErr);
843       
844       if(theErr && *theErr < 0)
845         return;
846       
847       MED::TNodeInfo& anInfo = const_cast<MED::TNodeInfo&>(theInfo);
848       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
849       
850       TValueHolder<TString, char>                aMeshName    (aMeshInfo.myName);
851       TValueHolder<TNodeCoord, med_float>        aCoord       (anInfo.myCoord);
852       TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch  (anInfo.myModeSwitch);
853       TValueHolder<ERepere, med_axis_type>       aSystem      (anInfo.mySystem);
854       TValueHolder<TString, char>                aCoordNames  (anInfo.myCoordNames);
855       TValueHolder<TString, char>                aCoordUnits  (anInfo.myCoordUnits);
856       TValueHolder<TString, char>                anElemNames  (anInfo.myElemNames);
857       TValueHolder<EBooleen, med_bool>           anIsElemNames(anInfo.myIsElemNames);
858       TValueHolder<TElemNum, med_int>            anElemNum    (anInfo.myElemNum);
859       TValueHolder<EBooleen, med_bool>           anIsElemNum  (anInfo.myIsElemNum);
860       TValueHolder<TElemNum, med_int>            aFamNum      (anInfo.myFamNum);
861       TValueHolder<TInt, med_int>                aNbElem      (anInfo.myNbElem);
862
863       TErr aRet = MEDmeshNodeCoordinateWr(myFile->Id(),
864                                           &aMeshName,
865                                           MED_NO_DT,
866                                           MED_NO_IT,
867                                           MED_NO_DT,
868                                           aModeSwitch,
869                                           aNbElem,
870                                           &aCoord);
871                                           
872       MEDmeshEntityFamilyNumberWr(myFile->Id(),
873                                   &aMeshName,
874                                   MED_NO_DT,
875                                   MED_NO_IT,
876                                   MED_NODE,
877                                   MED_NO_GEOTYPE,
878                                   aNbElem,
879                                   &aFamNum);
880       if(anIsElemNames)
881         MEDmeshEntityNameWr(myFile->Id(),
882                             &aMeshName,
883                             MED_NO_DT,
884                             MED_NO_IT,
885                             MED_NODE,
886                             MED_NO_GEOTYPE,
887                             aNbElem,
888                             &anElemNames);
889       if(anIsElemNum)
890         MEDmeshEntityNumberWr(myFile->Id(),
891                               &aMeshName,
892                               MED_NO_DT,
893                               MED_NO_IT,
894                               MED_NODE,
895                               MED_NO_GEOTYPE,
896                               aNbElem,
897                               &anElemNum);
898       if(theErr) 
899         *theErr = aRet;
900       else if(aRet < 0)
901         EXCEPTION(std::runtime_error,"SetNodeInfo - MEDmeshNodeCoordinateWr(...)");
902     }
903     
904     //----------------------------------------------------------------------------
905     void
906     TVWrapper
907     ::SetNodeInfo(const MED::TNodeInfo& theInfo,
908                   TErr* theErr)
909     {
910       TErr aRet;
911       SetNodeInfo(theInfo,eLECTURE_ECRITURE,&aRet);
912       
913       if(aRet < 0)
914         SetNodeInfo(theInfo,eLECTURE_AJOUT,&aRet);
915
916       if(theErr) 
917         *theErr = aRet;
918     }
919
920     //-----------------------------------------------------------------
921     void
922     TVWrapper
923     ::GetPolygoneInfo(MED::TPolygoneInfo& theInfo,
924                       TErr* theErr)
925     {
926       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
927
928       if(theErr && *theErr < 0)
929         return;
930
931       MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
932
933       TValueHolder<TString, char                       > aMeshName(aMeshInfo.myName);
934       TValueHolder<TElemNum, med_int                   > anIndex  (theInfo.myIndex);
935       TValueHolder<TElemNum, med_int                   > aConn    (theInfo.myConn);
936       TValueHolder<EEntiteMaillage, med_entity_type    > anEntity (theInfo.myEntity);
937       TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theInfo.myGeom);
938       TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theInfo.myConnMode);
939       TInt aNbElem = (TInt)theInfo.myElemNum->size();
940
941       TErr aRet;
942       aRet = MEDmeshPolygon2Rd(myFile->Id(), &aMeshName,
943                                MED_NO_DT, MED_NO_IT,
944                                anEntity, aGeom,
945                                aConnMode, &anIndex, &aConn);
946
947       if(theErr) 
948         *theErr = aRet;
949       else if(aRet < 0)
950         EXCEPTION(std::runtime_error,"GetPolygoneInfo - MEDmeshPolygonRd(...)");
951
952       if(theInfo.myIsElemNames){
953         GetNames(theInfo,aNbElem,theInfo.myEntity,theInfo.myGeom,&aRet);
954         if(theErr) 
955           *theErr = aRet;
956       }
957
958       if(theInfo.myIsElemNum){
959         GetNumeration(theInfo,aNbElem,theInfo.myEntity,theInfo.myGeom,&aRet);
960         if(theErr) 
961           *theErr = aRet;
962       }
963
964       GetFamilies(theInfo,aNbElem,theInfo.myEntity,theInfo.myGeom,&aRet);
965       if(theErr) 
966         *theErr = aRet;
967     }
968     
969     //----------------------------------------------------------------------------
970     void
971     TVWrapper
972     ::SetPolygoneInfo(const MED::TPolygoneInfo& theInfo,
973                       TErr* theErr)
974     {
975       SetPolygoneInfo(theInfo,eLECTURE_ECRITURE,theErr);
976     }
977     
978     //----------------------------------------------------------------------------
979     void 
980     TVWrapper
981     ::SetPolygoneInfo(const MED::TPolygoneInfo& theInfo,
982                       EModeAcces theMode,
983                       TErr* theErr)
984     {
985       TFileWrapper aFileWrapper(myFile,theMode,theErr);
986       
987       if(theErr && *theErr < 0)
988         return;
989
990       MED::TPolygoneInfo& anInfo = const_cast<MED::TPolygoneInfo&>(theInfo);
991       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
992
993       TValueHolder<TString, char                       > aMeshName(aMeshInfo.myName);
994       TValueHolder<TElemNum, med_int                   > anIndex  (anInfo.myIndex);
995       TValueHolder<TElemNum, med_int                   > aConn    (anInfo.myConn);
996       TValueHolder<EEntiteMaillage, med_entity_type    > anEntity (anInfo.myEntity);
997       TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (anInfo.myGeom);
998       TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(anInfo.myConnMode);
999
1000       TErr aRet = MEDmeshPolygon2Wr(myFile->Id(), &aMeshName,
1001                                     MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
1002                                     anEntity, aGeom,
1003                                     aConnMode, anInfo.myNbElem + 1,
1004                                     &anIndex, &aConn);
1005       if(theErr)
1006         *theErr = aRet;
1007       else if(aRet < 0)
1008         EXCEPTION(std::runtime_error,"SetPolygoneInfo - MEDmeshPolygonWr(...)");
1009       
1010       SetNames(anInfo,theInfo.myEntity,anInfo.myGeom,&aRet);
1011       if(theErr) 
1012         *theErr = aRet;
1013       
1014       SetNumeration(anInfo,theInfo.myEntity,anInfo.myGeom,&aRet);
1015       if(theErr) 
1016         *theErr = aRet;
1017       
1018       SetFamilies(anInfo,theInfo.myEntity,anInfo.myGeom,&aRet);
1019       if(theErr) 
1020         *theErr = aRet;
1021     }
1022
1023     //----------------------------------------------------------------------------
1024     TInt 
1025     TVWrapper
1026     ::GetNbPolygones(const MED::TMeshInfo& theMeshInfo, 
1027                      EEntiteMaillage theEntity, 
1028                      EGeometrieElement theGeom, 
1029                      EConnectivite theConnMode,
1030                      TErr* theErr)
1031     {
1032       return GetNbCells(theMeshInfo,theEntity,theGeom,theConnMode,theErr);
1033     }
1034     
1035     //----------------------------------------------------------------------------
1036     TInt 
1037     TVWrapper
1038     ::GetPolygoneConnSize(const MED::TMeshInfo& theMeshInfo, 
1039                           EEntiteMaillage theEntity, 
1040                           EGeometrieElement theGeom, 
1041                           EConnectivite theConnMode,
1042                           TErr* theErr)
1043     {
1044       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1045
1046       if(theErr && *theErr < 0)
1047         return 0;
1048
1049       MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1050       
1051       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1052       med_int aTaille = 0;
1053       med_bool chgt,trsf;
1054       aTaille=MEDmeshnEntity(myFile->Id(),
1055                              &aMeshName,
1056                              MED_NO_DT,
1057                              MED_NO_IT,
1058                              med_entity_type(theEntity),
1059                              med_geometry_type(theGeom),
1060                              MED_CONNECTIVITY,
1061                              med_connectivity_mode(theConnMode),
1062                              &chgt,
1063                              &trsf);
1064
1065       
1066       if(aTaille < 0)
1067         EXCEPTION(std::runtime_error,"GetPolygoneInfo - MEDmeshnEntity(...)");
1068
1069       return TInt(aTaille);
1070     }
1071
1072     //-----------------------------------------------------------------
1073     void 
1074     TVWrapper
1075     ::GetPolyedreInfo(TPolyedreInfo& theInfo,
1076                       TErr* theErr)
1077     {
1078       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1079
1080       if(theErr && *theErr < 0)
1081         return;
1082
1083       MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
1084
1085       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1086       TInt aNbElem = (TInt)theInfo.myElemNum->size();
1087       TValueHolder<TElemNum, med_int> anIndex(theInfo.myIndex);
1088       TValueHolder<TElemNum, med_int> aFaces(theInfo.myFaces);
1089       TValueHolder<TElemNum, med_int> aConn(theInfo.myConn);
1090       TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theInfo.myConnMode);
1091
1092       TErr aRet;
1093       aRet = MEDmeshPolyhedronRd(myFile->Id(),
1094                                  &aMeshName,
1095                                  MED_NO_DT,
1096                                  MED_NO_IT,
1097                                  MED_CELL,
1098                                  aConnMode,
1099                                  &anIndex,
1100                                  &aFaces,
1101                                  &aConn);
1102
1103       if(theErr) 
1104         *theErr = aRet;
1105       else if(aRet < 0)
1106         EXCEPTION(std::runtime_error,"GetPolygoneInfo - MEDmeshPolyhedronRd(...)");
1107
1108       if(theInfo.myIsElemNames){
1109         GetNames(theInfo,aNbElem,theInfo.myEntity,ePOLYEDRE,&aRet);
1110         if(theErr)
1111           *theErr = aRet;
1112       }
1113
1114       if(theInfo.myIsElemNum){
1115         GetNumeration(theInfo,aNbElem,theInfo.myEntity,ePOLYEDRE,&aRet);
1116         if(theErr) 
1117           *theErr = aRet;
1118       }
1119
1120       GetFamilies(theInfo,aNbElem,theInfo.myEntity,ePOLYEDRE,&aRet);
1121       if(theErr) 
1122         *theErr = aRet;
1123     }
1124
1125     //----------------------------------------------------------------------------
1126     void
1127     TVWrapper
1128     ::SetPolyedreInfo(const TPolyedreInfo& theInfo,
1129                       TErr* theErr)
1130     {
1131       SetPolyedreInfo(theInfo,eLECTURE_ECRITURE,theErr);
1132     }
1133     
1134     //----------------------------------------------------------------------------
1135     void 
1136     TVWrapper
1137     ::SetPolyedreInfo(const MED::TPolyedreInfo& theInfo,
1138                       EModeAcces theMode,
1139                       TErr* theErr)
1140     {
1141       TFileWrapper aFileWrapper(myFile,theMode,theErr);
1142       
1143       if(theErr && *theErr < 0)
1144         return;
1145
1146       MED::TPolyedreInfo& anInfo = const_cast<MED::TPolyedreInfo&>(theInfo);
1147       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1148
1149       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1150       TValueHolder<TElemNum, med_int> anIndex(anInfo.myIndex);
1151       TValueHolder<TElemNum, med_int> aFaces(anInfo.myFaces);
1152       TValueHolder<TElemNum, med_int> aConn(anInfo.myConn);
1153       TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(anInfo.myConnMode);
1154
1155       TErr aRet;
1156       aRet = MEDmeshPolyhedronWr(myFile->Id(),
1157                                  &aMeshName,
1158                                  MED_NO_DT,
1159                                  MED_NO_IT,
1160                                  MED_UNDEF_DT,
1161                                  MED_CELL,
1162                                  aConnMode,
1163                                  anInfo.myNbElem+1,
1164                                  &anIndex,
1165                                  (TInt)anInfo.myFaces->size(),
1166                                  &aFaces,
1167                                  &aConn);
1168       
1169       if(theErr) 
1170         *theErr = aRet;
1171       else if(aRet < 0)
1172         EXCEPTION(std::runtime_error,"SetPolyedreInfo - MEDmeshPolyhedronWr(...)");
1173       
1174       TValueHolder<EEntiteMaillage, med_entity_type> anEntity(anInfo.myEntity);
1175
1176       if(theInfo.myIsElemNames){
1177         TValueHolder<TString, char> anElemNames(anInfo.myElemNames);
1178         aRet  = MEDmeshEntityNameWr(myFile->Id(),
1179                                     &aMeshName,
1180                                     MED_NO_DT,
1181                                     MED_NO_IT,
1182                                     anEntity,
1183                                     MED_POLYHEDRON,
1184                                     (TInt)anInfo.myElemNames->size(),
1185                                     &anElemNames);
1186         if(theErr) 
1187           *theErr = aRet;
1188         else if(aRet < 0)
1189           EXCEPTION(std::runtime_error,"SetPolyedreInfo - MEDmeshEntityNameWr(...)");
1190       }
1191       
1192       if(theInfo.myIsElemNum){
1193         TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
1194         aRet = MEDmeshEntityNumberWr(myFile->Id(),
1195                                      &aMeshName,
1196                                      MED_NO_DT,
1197                                      MED_NO_IT,
1198                                      anEntity,
1199                                      MED_POLYHEDRON,
1200                                      (TInt)anInfo.myElemNum->size(),
1201                                      &anElemNum);
1202         if(theErr) 
1203           *theErr = aRet;
1204         else if(aRet < 0)
1205           EXCEPTION(std::runtime_error,"SetPolyedreInfo - MEDmeshEntityNumberWr(...)");
1206       }
1207       
1208       
1209       TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum);
1210       aRet = MEDmeshEntityFamilyNumberWr(myFile->Id(),
1211                                          &aMeshName,
1212                                          MED_NO_DT,
1213                                          MED_NO_IT,
1214                                          anEntity,
1215                                          MED_POLYHEDRON,
1216                                          (TInt)anInfo.myFamNum->size(),
1217                                          &aFamNum);
1218       
1219       if(theErr) 
1220         *theErr = aRet;
1221       else if(aRet < 0)
1222         EXCEPTION(std::runtime_error,"SetPolyedreInfo - MEDmeshEntityFamilyNumberWr(...)");
1223     }
1224
1225     //----------------------------------------------------------------------------
1226     TInt
1227     TVWrapper
1228     ::GetNbPolyedres(const MED::TMeshInfo& theMeshInfo, 
1229                      EEntiteMaillage theEntity, 
1230                      EGeometrieElement theGeom, 
1231                      EConnectivite theConnMode,
1232                      TErr* theErr)
1233     {
1234       return GetNbCells(theMeshInfo,theEntity,theGeom,theConnMode,theErr);
1235     }
1236
1237     //----------------------------------------------------------------------------
1238     void
1239     TVWrapper    ::GetPolyedreConnSize(const TMeshInfo& theMeshInfo,
1240                           TInt& theNbFaces,
1241                           TInt& theConnSize,
1242                           EConnectivite theConnMode,
1243                           TErr* theErr)
1244     {
1245       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1246
1247       if(theErr && *theErr < 0) 
1248         EXCEPTION(std::runtime_error,"GetPolyedreConnSize - (...)");
1249
1250       MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1251       
1252       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1253       TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theConnMode);
1254       //TValueHolder<TInt, med_int> aNbFaces(theNbFaces);
1255       //TValueHolder<TInt, med_int> aConnSize(theConnSize);
1256
1257       med_bool chgt,trsf;
1258       theNbFaces = MEDmeshnEntity(myFile->Id(),
1259                                   &aMeshName,
1260                                   MED_NO_DT,
1261                                   MED_NO_IT,
1262                                   MED_CELL,
1263                                   MED_POLYHEDRON,
1264                                   MED_INDEX_NODE,
1265                                   aConnMode,
1266                                   &chgt,
1267                                   &trsf);
1268
1269       theConnSize = MEDmeshnEntity(myFile->Id(),
1270                                   &aMeshName,
1271                                   MED_NO_DT,
1272                                   MED_NO_IT,
1273                                   MED_CELL,
1274                                   MED_POLYHEDRON,
1275                                   MED_CONNECTIVITY,
1276                                   aConnMode,
1277                                   &chgt,
1278                                   &trsf);
1279
1280       if(theNbFaces < 0 || theConnSize<0)
1281         EXCEPTION(std::runtime_error,"GetPolygoneInfo - MEDmeshnEntity(...)");
1282
1283     }
1284     
1285     //-----------------------------------------------------------------
1286     TEntityInfo
1287     TVWrapper
1288     ::GetEntityInfo(const MED::TMeshInfo& theMeshInfo,
1289                     EConnectivite theConnMode,
1290                     TErr* theErr)
1291     {
1292       TEntityInfo anInfo;
1293       
1294       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1295       
1296       if(theErr && *theErr < 0)
1297         return anInfo;
1298
1299       if(theMeshInfo.GetType() == eNON_STRUCTURE) {
1300         TInt aNbElem = GetNbNodes(theMeshInfo);
1301         if(aNbElem > 0){
1302           anInfo[eNOEUD][ePOINT1] = aNbElem;
1303           const TEntity2GeomSet& anEntity2GeomSet = GetEntity2GeomSet();
1304           TEntity2GeomSet::const_iterator anIter = anEntity2GeomSet.begin();
1305           TEntity2GeomSet::const_iterator anIterEnd = anEntity2GeomSet.end();
1306           for(; anIter != anIterEnd; anIter++){
1307             const EEntiteMaillage& anEntity = anIter->first;
1308             const TGeomSet& aGeomSet = anIter->second;
1309             TGeomSet::const_iterator anIter2 = aGeomSet.begin();
1310             TGeomSet::const_iterator anIterEnd2 = aGeomSet.end();
1311             for(; anIter2 != anIterEnd2; anIter2++){
1312               const EGeometrieElement& aGeom = *anIter2;
1313               aNbElem = GetNbCells(theMeshInfo,anEntity,aGeom,theConnMode,theErr);
1314               if(aNbElem > 0) {
1315                 if ( anEntity == eSTRUCT_ELEMENT ) {
1316                   const TInt nbStructTypes = aNbElem;
1317                   for ( TInt structType = 0; structType < nbStructTypes; ++structType ) {
1318                     // check type name to keep only "MED_BALL" structured element
1319                     TValueHolder<TString, char> aMeshName((TString&) theMeshInfo.myName );
1320                     char                        geotypename[ MED_NAME_SIZE + 1] = "";
1321                     med_geometry_type           geotype;
1322                     MEDmeshEntityInfo( myFile->Id(), &aMeshName, MED_NO_DT, MED_NO_IT,
1323                                        med_entity_type(anEntity), structType+1,
1324                                        geotypename, &geotype);
1325                     if ( strcmp( geotypename, MED_BALL_NAME ) == 0 ) {
1326                       aNbElem = GetNbCells( theMeshInfo, anEntity, EGeometrieElement(geotype),
1327                                             theConnMode, theErr);
1328                       if ( aNbElem > 0 )
1329                         anInfo[anEntity][EGeometrieElement(geotype)] = aNbElem;
1330                     }
1331                   }
1332                 }
1333                 else {
1334                   anInfo[anEntity][aGeom] = aNbElem;
1335                 }
1336               }
1337             }
1338           }
1339         }
1340       } else { // eSTRUCTURE
1341         EGrilleType aGrilleType;
1342         TInt aNbNodes = 1;
1343         TInt aNbElem  = 1;
1344         TInt aNbSub   = 0;
1345         TInt aDim = theMeshInfo.GetDim();
1346         EGeometrieElement aGeom, aSubGeom;
1347         EEntiteMaillage aSubEntity = eMAILLE;
1348
1349         GetGrilleType(theMeshInfo, aGrilleType);
1350
1351         TIntVector aStruct(aDim);
1352         if(aGrilleType == eGRILLE_STANDARD)
1353         {
1354           GetGrilleStruct(theMeshInfo, aStruct, theErr);
1355         }
1356         else
1357         { // eGRILLE_CARTESIENNE and eGRILLE_POLAIRE
1358           ETable aTable[3] = { eCOOR_IND1, eCOOR_IND2, eCOOR_IND3 };
1359           for(med_int anAxis = 0; anAxis < aDim; anAxis++)
1360             aStruct[ anAxis ] = GetNbNodes(theMeshInfo, aTable[anAxis]);
1361         }
1362         for(med_int i = 0; i < aDim; i++){
1363           aNbNodes = aNbNodes * aStruct[i];
1364           aNbElem = aNbElem * (aStruct[i] - 1);
1365         }
1366         switch(aDim){
1367         case 1:
1368           aGeom = eSEG2;
1369           break;
1370         case 2:
1371           aGeom = eQUAD4;
1372           aSubGeom = eSEG2;
1373           aSubEntity = eARETE;
1374           aNbSub =
1375             (aStruct[0]  ) * (aStruct[1]-1) +
1376             (aStruct[0]-1) * (aStruct[1]  );
1377           break;
1378         case 3:
1379           aGeom = eHEXA8;
1380           aSubGeom = eQUAD4;
1381           aSubEntity = eFACE;
1382           aNbSub =
1383             (aStruct[0]  ) * (aStruct[1]-1) * (aStruct[2]-1) +
1384             (aStruct[0]-1) * (aStruct[1]  ) * (aStruct[2]-1) +
1385             (aStruct[0]-1) * (aStruct[1]-1) * (aStruct[2]  );
1386           break;
1387         }
1388         anInfo[eNOEUD][ePOINT1] = aNbNodes;
1389         anInfo[eMAILLE][aGeom] = aNbElem;
1390         if ( aDim > 1 )
1391           anInfo[aSubEntity][aSubGeom] = aNbSub;
1392       }
1393       return anInfo;
1394     }
1395
1396     //-----------------------------------------------------------------
1397     TInt TVWrapper::GetNbCells(const MED::TMeshInfo& theMeshInfo,
1398                                EEntiteMaillage theEntity,
1399                                EGeometrieElement theGeom,
1400                                EConnectivite theConnMode,
1401                                TErr* theErr)
1402     {
1403       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1404
1405       if(theErr && *theErr < 0)
1406         return -1;
1407
1408       MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1409       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1410       med_bool chgt,trsf;
1411       switch ( theGeom )
1412       {
1413       case MED::ePOLYGONE:
1414       case MED::ePOLYGON2:
1415       {
1416         return MEDmeshnEntity(myFile->Id(),&aMeshName,
1417                               MED_NO_DT,MED_NO_IT,
1418                               med_entity_type(theEntity),med_geometry_type(theGeom),
1419                               MED_INDEX_NODE,med_connectivity_mode(theConnMode),
1420                               &chgt,&trsf)-1;
1421       }
1422       case MED::ePOLYEDRE:
1423       {
1424         return MEDmeshnEntity(myFile->Id(),&aMeshName,
1425                               MED_NO_DT,MED_NO_IT,
1426                               med_entity_type(theEntity),MED_POLYHEDRON,
1427                               MED_INDEX_FACE,med_connectivity_mode(theConnMode),
1428                               &chgt,&trsf)-1;
1429       }
1430       case MED::eBALL:
1431       {
1432         return GetNbBalls( theMeshInfo );
1433       }
1434       default:
1435       {
1436         return MEDmeshnEntity(myFile->Id(),&aMeshName,
1437                               MED_NO_DT,MED_NO_IT,
1438                               med_entity_type(theEntity),med_geometry_type(theGeom),
1439                               MED_CONNECTIVITY,med_connectivity_mode(theConnMode),
1440                               &chgt,&trsf);
1441       }
1442       }
1443       return 0;
1444     }
1445
1446     //----------------------------------------------------------------------------
1447     void TVWrapper::GetCellInfo(MED::TCellInfo& theInfo, TErr* theErr)
1448     {
1449       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1450
1451       if(theErr && *theErr < 0)
1452         return;
1453
1454       MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
1455
1456       TValueHolder<TString, char>                        aMeshName    (aMeshInfo.myName);
1457       TValueHolder<TElemNum, med_int>                    aConn        (theInfo.myConn);
1458       TValueHolder<EModeSwitch, med_switch_mode>         aModeSwitch  (theInfo.myModeSwitch);
1459       TValueHolder<TString, char>                        anElemNames  (theInfo.myElemNames);
1460       TValueHolder<EBooleen, med_bool>                   anIsElemNames(theInfo.myIsElemNames);
1461       TValueHolder<TElemNum, med_int>                    anElemNum    (theInfo.myElemNum);
1462       TValueHolder<EBooleen, med_bool>                   anIsElemNum  (theInfo.myIsElemNum);
1463       TValueHolder<TElemNum, med_int>                    aFamNum      (theInfo.myFamNum);
1464       TValueHolder<EBooleen, med_bool>                   anIsFamNum   (theInfo.myIsFamNum);
1465       TValueHolder<EEntiteMaillage, med_entity_type>     anEntity     (theInfo.myEntity);
1466       TValueHolder<EGeometrieElement, med_geometry_type> aGeom        (theInfo.myGeom);
1467       TValueHolder<EConnectivite, med_connectivity_mode> aConnMode    (theInfo.myConnMode);
1468
1469       TErr aRet;
1470       aRet = MEDmeshElementRd(myFile->Id(),
1471                               &aMeshName,
1472                               MED_NO_DT,
1473                               MED_NO_IT,
1474                               anEntity,
1475                               aGeom,
1476                               aConnMode,
1477                               aModeSwitch,
1478                               &aConn,
1479                               &anIsElemNames,
1480                               &anElemNames,
1481                               &anIsElemNum,
1482                               &anElemNum,
1483                               &anIsFamNum,
1484                               &aFamNum);
1485
1486       if(theErr) 
1487         *theErr = aRet;
1488       else if(aRet < 0)
1489         EXCEPTION(std::runtime_error,"GetCellInfo - MEDmeshElementRd(...)");
1490       
1491       if (anIsFamNum == MED_FALSE)
1492         {
1493           int mySize = (int) theInfo.myFamNum->size();
1494           theInfo.myFamNum->clear();
1495           theInfo.myFamNum->resize(mySize, 0);
1496         }
1497       
1498     }
1499     
1500     //----------------------------------------------------------------------------
1501     void
1502     TVWrapper
1503     ::SetCellInfo(const MED::TCellInfo& theInfo,
1504                   EModeAcces theMode,
1505                   TErr* theErr)
1506     {
1507       TFileWrapper aFileWrapper(myFile,theMode,theErr);
1508       
1509       if(theErr && *theErr < 0)
1510         return;
1511
1512       MED::TCellInfo& anInfo    = const_cast<MED::TCellInfo&>(theInfo);
1513       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1514
1515       TValueHolder<TString, char>                        aMeshName    (aMeshInfo.myName);
1516       TValueHolder<TElemNum, med_int>                    aConn        (anInfo.myConn);
1517       TValueHolder<EModeSwitch, med_switch_mode>         aModeSwitch  (anInfo.myModeSwitch);
1518       TValueHolder<TString, char>                        anElemNames  (anInfo.myElemNames);
1519       TValueHolder<EBooleen, med_bool>                   anIsElemNames(anInfo.myIsElemNames);
1520       TValueHolder<TElemNum, med_int>                    anElemNum    (anInfo.myElemNum);
1521       TValueHolder<EBooleen, med_bool>                   anIsElemNum  (anInfo.myIsElemNum);
1522       TValueHolder<TElemNum, med_int>                    aFamNum      (anInfo.myFamNum);
1523       TValueHolder<EBooleen, med_bool>                   anIsFamNum   (anInfo.myIsFamNum);
1524       TValueHolder<EEntiteMaillage, med_entity_type>     anEntity     (anInfo.myEntity);
1525       TValueHolder<EGeometrieElement, med_geometry_type> aGeom        (anInfo.myGeom);
1526       TValueHolder<EConnectivite, med_connectivity_mode> aConnMode    (anInfo.myConnMode);
1527       TValueHolder<TInt, med_int>                        aNbElem      (anInfo.myNbElem);
1528
1529       TErr aRet;
1530       aRet = MEDmeshElementConnectivityWr(myFile->Id(),
1531                                           &aMeshName,
1532                                           MED_NO_DT,
1533                                           MED_NO_IT,
1534                                           MED_UNDEF_DT,
1535                                           anEntity,
1536                                           aGeom,
1537                                           aConnMode,
1538                                           aModeSwitch,
1539                                           aNbElem,
1540                                           &aConn);
1541
1542       MEDmeshEntityFamilyNumberWr(myFile->Id(),
1543                                   &aMeshName,
1544                                   MED_NO_DT,
1545                                   MED_NO_IT,
1546                                   anEntity,
1547                                   aGeom,
1548                                   aNbElem,
1549                                   &aFamNum);
1550       if(anIsElemNames)
1551         MEDmeshEntityNameWr(myFile->Id(),
1552                             &aMeshName,
1553                             MED_NO_DT,
1554                             MED_NO_IT,
1555                             anEntity,
1556                             aGeom,
1557                             aNbElem,
1558                             &anElemNames);
1559       if(anIsElemNum)
1560         MEDmeshEntityNumberWr(myFile->Id(),
1561                               &aMeshName,
1562                               MED_NO_DT,
1563                               MED_NO_IT,
1564                               anEntity,
1565                               aGeom,
1566                               aNbElem,
1567                               &anElemNum);
1568       if(theErr) 
1569         *theErr = aRet;
1570       else if(aRet < 0)
1571         EXCEPTION(std::runtime_error,"SetCellInfo - MEDmeshElementWr(...)");
1572     }
1573
1574     //----------------------------------------------------------------------------
1575     void
1576     TVWrapper
1577     ::SetCellInfo(const MED::TCellInfo& theInfo,
1578                   TErr* theErr)
1579     {
1580       SetCellInfo(theInfo,eLECTURE_ECRITURE,theErr);
1581     }
1582
1583     //----------------------------------------------------------------------------
1584     //! Read geom type of MED_BALL structural element
1585     EGeometrieElement TVWrapper::GetBallGeom(const TMeshInfo& theMeshInfo)
1586     {
1587       TFileWrapper aFileWrapper(myFile,eLECTURE);
1588
1589       // read med_geometry_type of "MED_BALL" element
1590       char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME;
1591       return EGeometrieElement( MEDstructElementGeotype( myFile->Id(), geotypename ) );
1592     }
1593
1594     //----------------------------------------------------------------------------
1595     //! Read number of balls in the Mesh
1596     TInt TVWrapper::GetNbBalls(const TMeshInfo& theMeshInfo)
1597     {
1598       TFileWrapper aFileWrapper(myFile,eLECTURE);
1599
1600       EGeometrieElement ballType = GetBallGeom( theMeshInfo );
1601       if ( ballType < 0 )
1602         return 0;
1603
1604       return GetNbCells( theMeshInfo, eSTRUCT_ELEMENT, ballType, eNOD );
1605     }
1606
1607     //----------------------------------------------------------------------------
1608     //! Read a MEDWrapped representation of MED_BALL from the MED file
1609     void TVWrapper::GetBallInfo(TBallInfo& theInfo, TErr* theErr)
1610     {
1611       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1612
1613       // check geometry of MED_BALL
1614       if ( theInfo.myGeom == eBALL )
1615       {
1616         theInfo.myGeom = GetBallGeom( *theInfo.myMeshInfo );
1617         if ( theInfo.myGeom < 0 ) {
1618           if ( !theErr )
1619             EXCEPTION(std::runtime_error,"GetBallInfo - no balls in the mesh");
1620           *theErr = theInfo.myGeom;
1621           return;
1622         }
1623       }
1624
1625       // read nodes ids
1626       GetCellInfo( theInfo );
1627
1628       // read diameters
1629       TValueHolder<TString, char>                        aMeshName (theInfo.myMeshInfo->myName);
1630       TValueHolder<EGeometrieElement, med_geometry_type> aGeom     (theInfo.myGeom);
1631       TValueHolder<TFloatVector, void>                   aDiam     (theInfo.myDiameters);
1632       char varattname[ MED_NAME_SIZE + 1] = MED_BALL_DIAMETER;
1633
1634       TErr aRet = MEDmeshStructElementVarAttRd( myFile->Id(), &aMeshName,
1635                                                 MED_NO_DT, MED_NO_IT,
1636                                                 aGeom,
1637                                                 varattname,
1638                                                 &aDiam);
1639       if ( theErr )
1640         *theErr = aRet;
1641       else if ( aRet < 0 )
1642         EXCEPTION(std::runtime_error,"GetBallInfo - pb at reading diameters");
1643     }
1644
1645     //----------------------------------------------------------------------------
1646     //! Write a MEDWrapped representation of MED_BALL to the MED file
1647     void  TVWrapper::SetBallInfo(const TBallInfo& theInfo, EModeAcces theMode, TErr* theErr)
1648     {
1649       TFileWrapper aFileWrapper(myFile,theMode,theErr);
1650
1651       TErr ret;
1652       char ballsupportname[MED_NAME_SIZE+1]="BALL_SUPPORT_MESH";
1653       EGeometrieElement ballGeom = GetBallGeom( *theInfo.myMeshInfo );
1654       if ( ballGeom < 0 )
1655       {
1656         // no ball model in the file, create support mesh for it
1657         char dummyname [MED_NAME_SIZE*3+1]="";
1658         if (( ret = MEDsupportMeshCr( myFile->Id(),
1659                                       ballsupportname,
1660                                       theInfo.myMeshInfo->GetSpaceDim(),
1661                                       theInfo.myMeshInfo->GetDim(),
1662                                       "Support mesh for a ball model",
1663                                       MED_CARTESIAN,
1664                                       /*axisname=*/dummyname, /*unitname=*/dummyname)) < 0) {
1665           if ( !theErr )
1666             EXCEPTION(std::runtime_error,"SetBallInfo - MEDsupportMeshCr");
1667           *theErr = ret;
1668           return;
1669         }
1670         // write coordinates of 1 node
1671         med_float coord[3] = {0,0,0};
1672         if ((ret = MEDmeshNodeCoordinateWr(myFile->Id(),
1673                                            ballsupportname, MED_NO_DT, MED_NO_IT, 0.0,
1674                                            MED_FULL_INTERLACE, /*nnode=*/1, coord)) < 0) {
1675           if ( !theErr )
1676             EXCEPTION(std::runtime_error,"SetBallInfo - MEDmeshNodeCoordinateWr");
1677           *theErr = ret;
1678           return;
1679         }
1680         // ball model creation
1681         char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME;
1682         if (( ballGeom = (EGeometrieElement) MEDstructElementCr(myFile->Id(),
1683                                                                 geotypename,
1684                                                                 theInfo.myMeshInfo->GetSpaceDim(),
1685                                                                 ballsupportname,
1686                                                                 MED_NODE,MED_NONE)) < 0 ) {
1687           if ( !theErr )
1688             EXCEPTION(std::runtime_error,"SetBallInfo - MEDstructElementCr");
1689           *theErr = ret;
1690           return;
1691         }
1692         // create diameter attribute
1693         if (( ret = MEDstructElementVarAttCr(myFile->Id(),
1694                                              geotypename, MED_BALL_DIAMETER,
1695                                              MED_ATT_FLOAT64, /*ncomp=*/1)) < 0) {
1696           if ( !theErr )
1697             EXCEPTION(std::runtime_error,"SetBallInfo - MEDstructElementVarAttCr");
1698           *theErr = ret;
1699           return;
1700         }
1701       } // ballGeom < 0
1702
1703       TBallInfo& aBallInfo = ((TBallInfo&) theInfo );
1704       aBallInfo.myGeom = ballGeom;
1705
1706       // write node ids
1707       SetCellInfo(theInfo,theMode,theErr);
1708       if ( theErr && theErr < 0 )
1709         return;
1710
1711       // write diameter
1712       TValueHolder<TString, char>                        aMeshName (aBallInfo.myMeshInfo->myName);
1713       TValueHolder<EGeometrieElement, med_geometry_type> aGeom     (aBallInfo.myGeom);
1714       TValueHolder<TFloatVector, void>                   aDiam     (aBallInfo.myDiameters);
1715       ret = MEDmeshStructElementVarAttWr(myFile->Id(), &aMeshName,
1716                                          MED_NO_DT, MED_NO_IT,
1717                                          aGeom, MED_BALL_DIAMETER,
1718                                          theInfo.myNbElem, &aDiam);
1719       if ( theErr )
1720         *theErr = ret;
1721       else if ( ret < 0 )
1722         EXCEPTION(std::runtime_error,"SetBallInfo - MEDmeshStructElementVarAttWr");
1723     }
1724
1725     //----------------------------------------------------------------------------
1726     //! Write a MEDWrapped representation of MED_BALL to the MED file
1727     void  TVWrapper::SetBallInfo(const TBallInfo& theInfo, TErr* theErr)
1728     {
1729       SetBallInfo( theInfo, eLECTURE_ECRITURE, theErr );
1730     }
1731
1732     //-----------------------------------------------------------------
1733     TInt
1734     TVWrapper
1735     ::GetNbFields(TErr* theErr)
1736     {
1737       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1738       
1739       if(theErr && *theErr < 0)
1740         return -1;
1741       
1742       return MEDnField(myFile->Id());
1743     }
1744     
1745     //----------------------------------------------------------------------------
1746     TInt
1747     TVWrapper
1748     ::GetNbComp(TInt theFieldId,
1749                 TErr* theErr)
1750     {
1751       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1752       
1753       if(theErr && *theErr < 0)
1754         return -1;
1755       
1756       return MEDfieldnComponent(myFile->Id(),theFieldId);
1757     }
1758     
1759     //----------------------------------------------------------------------------
1760     void
1761     TVWrapper
1762     ::GetFieldInfo(TInt theFieldId, 
1763                    MED::TFieldInfo& theInfo,
1764                    TErr* theErr)
1765     {
1766       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1767       
1768       if(theErr && *theErr < 0)
1769         return;
1770       
1771       TString aFieldName(256); // Protect from memory problems with too long names
1772       TValueHolder<ETypeChamp, med_field_type> aType(theInfo.myType);
1773       TValueHolder<TString, char> aCompNames(theInfo.myCompNames);
1774       TValueHolder<TString, char> anUnitNames(theInfo.myUnitNames);
1775       MED::TMeshInfo& aMeshInfo = theInfo.myMeshInfo;
1776       
1777       TErr aRet;
1778       med_bool local;
1779       char dtunit[MED_SNAME_SIZE+1];
1780           char local_mesh_name[MED_NAME_SIZE+1]="";
1781       med_int nbofstp;
1782       theInfo.myNbComp = MEDfieldnComponent(myFile->Id(),theFieldId);
1783       aRet = MEDfieldInfo(myFile->Id(),
1784                           theFieldId,
1785                           &aFieldName[0],
1786                           local_mesh_name,
1787                           &local,
1788                           &aType,
1789                           &aCompNames,
1790                           &anUnitNames,
1791                           dtunit,
1792                           &nbofstp);
1793
1794           if(strcmp(&aMeshInfo.myName[0],local_mesh_name) != 0 ) {
1795                   if(theErr)
1796                         *theErr = -1;
1797                   return;
1798           }
1799
1800       theInfo.SetName(aFieldName);
1801
1802       if(theErr)
1803         *theErr = aRet;
1804       else if(aRet < 0)
1805         EXCEPTION(std::runtime_error,"GetFieldInfo - MEDfieldInfo(...)");
1806     }
1807     
1808     //----------------------------------------------------------------------------
1809     void
1810     TVWrapper
1811     ::SetFieldInfo(const MED::TFieldInfo& theInfo,
1812                    EModeAcces theMode,
1813                    TErr* theErr)
1814     {
1815       TFileWrapper aFileWrapper(myFile,theMode,theErr);
1816       
1817       if(theErr && *theErr < 0)
1818         return;
1819       
1820       MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
1821       
1822       TValueHolder<TString, char> aFieldName(anInfo.myName);
1823       TValueHolder<ETypeChamp, med_field_type> aType(anInfo.myType);
1824       TValueHolder<TString, char> aCompNames(anInfo.myCompNames);
1825       TValueHolder<TString, char> anUnitNames(anInfo.myUnitNames);
1826       MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo;
1827       TErr aRet;
1828       char dtunit[MED_SNAME_SIZE+1];
1829       std::fill(dtunit,dtunit+MED_SNAME_SIZE+1,'\0');
1830       aRet = MEDfieldCr(myFile->Id(),
1831                         &aFieldName,
1832                         aType,
1833                         anInfo.myNbComp,
1834                         &aCompNames,
1835                         &anUnitNames,
1836                         dtunit,
1837                         &aMeshInfo.myName[0]);
1838       if(theErr) 
1839         *theErr = aRet;
1840       else if(aRet < 0)
1841         EXCEPTION(std::runtime_error,"SetFieldInfo - MEDfieldCr(...)");
1842     }
1843     
1844     //----------------------------------------------------------------------------
1845     void
1846     TVWrapper
1847     ::SetFieldInfo(const MED::TFieldInfo& theInfo,
1848                    TErr* theErr)
1849     {
1850       TErr aRet;
1851       SetFieldInfo(theInfo,eLECTURE_ECRITURE,&aRet);
1852       
1853       if(aRet < 0)
1854         SetFieldInfo(theInfo,eLECTURE_AJOUT,&aRet);
1855
1856       if(theErr) 
1857         *theErr = aRet;
1858     }
1859     
1860     //----------------------------------------------------------------------------
1861     TInt
1862     TVWrapper
1863     ::GetNbGauss(TErr* theErr)
1864     {
1865       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1866       
1867       if(theErr && *theErr < 0)
1868         return -1;
1869       
1870       return MEDnLocalization(myFile->Id());
1871     }
1872
1873     //----------------------------------------------------------------------------
1874     TGaussInfo::TInfo
1875     TVWrapper
1876     ::GetGaussPreInfo(TInt theId, 
1877                       TErr* theErr)
1878     {
1879       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1880
1881       if(theErr && *theErr < 0)
1882         return TGaussInfo::TInfo( TGaussInfo::TKey(ePOINT1,""),0 );
1883       
1884       med_int aNbGaussPoints = med_int();
1885       TVector<char> aName(GetNOMLength()+1);
1886       med_geometry_type aGeom = MED_NONE;
1887
1888       TErr aRet;
1889       med_int dim;
1890       char geointerpname[MED_NAME_SIZE+1]="";
1891       char ipointstructmeshname[MED_NAME_SIZE+1]="";
1892       med_int nsectionmeshcell;
1893       med_geometry_type sectiongeotype;
1894       aRet = MEDlocalizationInfo (myFile->Id(),
1895                                   theId,
1896                                   &aName[0],
1897                                   &aGeom,
1898                                   &dim,
1899                                   &aNbGaussPoints,
1900                                   geointerpname,
1901                                   ipointstructmeshname,
1902                                   &nsectionmeshcell,
1903                                   &sectiongeotype);
1904       if(theErr) 
1905         *theErr = aRet;
1906       else if(aRet < 0)
1907         EXCEPTION(std::runtime_error,"GetGaussPreInfo - MEDlocalizationInfo(...)");
1908       return TGaussInfo::TInfo(TGaussInfo::TKey(EGeometrieElement(aGeom),&aName[0]),
1909                                TInt(aNbGaussPoints));
1910     }
1911
1912     //----------------------------------------------------------------------------
1913     void
1914     TVWrapper
1915     ::GetGaussInfo(TInt theId, 
1916                    TGaussInfo& theInfo,
1917                    TErr* theErr)
1918     {
1919       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1920       
1921       if(theErr && *theErr < 0)
1922         return;
1923       
1924       TValueHolder<TNodeCoord, med_float> aRefCoord(theInfo.myRefCoord);
1925       TValueHolder<TNodeCoord, med_float> aGaussCoord(theInfo.myGaussCoord);
1926       TValueHolder<TWeight, med_float> aWeight(theInfo.myWeight);
1927       TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
1928       TValueHolder<TString, char> aGaussName(theInfo.myName);
1929
1930       TErr aRet;
1931       aRet = MEDlocalizationRd(myFile->Id(),
1932                                &aGaussName,
1933                                aModeSwitch,
1934                                &aRefCoord,
1935                                &aGaussCoord,
1936                                &aWeight);
1937
1938       if(theErr) 
1939         *theErr = aRet;
1940       else if(aRet < 0)
1941         EXCEPTION(std::runtime_error,"GetGaussInfo - MEDlocalizationRd(...)");
1942     }
1943
1944     //----------------------------------------------------------------------------
1945     TInt
1946     TVWrapper
1947     ::GetNbProfiles(TErr* theErr)
1948     {
1949       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1950       
1951       if(theErr && *theErr < 0)
1952         return -1;
1953       
1954       return MEDnProfile(myFile->Id());
1955     }
1956
1957     TProfileInfo::TInfo
1958     TVWrapper
1959     ::GetProfilePreInfo(TInt theId, 
1960                         TErr* theErr)
1961     {
1962       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1963
1964       if(theErr && *theErr < 0)
1965         return TProfileInfo::TInfo();
1966       
1967       med_int aSize = -1;
1968       TVector<char> aName(GetNOMLength()+1);
1969
1970       TErr aRet;
1971       aRet = MEDprofileInfo(myFile->Id(),
1972                             theId,
1973                             &aName[0],
1974                             &aSize);
1975       if(theErr) 
1976         *theErr = aRet;
1977       else if(aRet < 0)
1978         EXCEPTION(std::runtime_error,"GetProfilePreInfo - MEDprofileInfo(...)");
1979       
1980       return TProfileInfo::TInfo(&aName[0],aSize);
1981     }
1982
1983     void
1984     TVWrapper
1985     ::GetProfileInfo(TInt theId, 
1986                      TProfileInfo& theInfo,
1987                      TErr* theErr)
1988     {
1989       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
1990       
1991       if(theErr && *theErr < 0)
1992         return;
1993       
1994       TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo);
1995       TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
1996       TValueHolder<TString, char>     aProfileName(anInfo.myName);
1997
1998       TErr aRet;
1999       aRet = MEDprofileRd(myFile->Id(),
2000                           &aProfileName,
2001                           &anElemNum);
2002       if(theErr) 
2003         *theErr = aRet;
2004       else if(aRet < 0)
2005         EXCEPTION(std::runtime_error,"GetProfileInfo - MEDprofileRd(...)");
2006     }
2007
2008     void
2009     TVWrapper
2010     ::SetProfileInfo(const TProfileInfo& theInfo,
2011                      EModeAcces          theMode,
2012                      TErr*               theErr)
2013     {
2014       TFileWrapper aFileWrapper(myFile,theMode,theErr);
2015       
2016       if(theErr && *theErr < 0)
2017         return;
2018       
2019       TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo);
2020       TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
2021       TValueHolder<TString, char>     aProfileName(anInfo.myName);
2022
2023       TErr aRet;
2024       aRet = MEDprofileWr(myFile->Id(),      // descripteur du fichier.
2025                           &aProfileName,        // tableau de valeurs du profil.
2026                           theInfo.GetSize(), // taille du profil.
2027                           &anElemNum);    // nom profil.
2028       if(theErr)
2029         *theErr = aRet;
2030       else if(aRet < 0)
2031         EXCEPTION(std::runtime_error,"SetProfileInfo - MEDprofileWr(...)");
2032     }
2033
2034     void
2035     TVWrapper
2036     ::SetProfileInfo(const TProfileInfo& theInfo,
2037                      TErr*               theErr)
2038     {
2039       TErr aRet;
2040       SetProfileInfo(theInfo,eLECTURE_ECRITURE,&aRet);
2041       
2042       if(aRet < 0)
2043         SetProfileInfo(theInfo,eLECTURE_AJOUT,&aRet);
2044
2045       if(aRet < 0)
2046         SetProfileInfo(theInfo,eCREATION,&aRet);
2047
2048       if(theErr)
2049         *theErr = aRet;
2050     }
2051
2052     //-----------------------------------------------------------------
2053     TInt
2054     TVWrapper
2055     ::GetNbTimeStamps(const MED::TFieldInfo& theInfo, 
2056                       const MED::TEntityInfo& theEntityInfo,
2057                       EEntiteMaillage& theEntity,
2058                       TGeom2Size& theGeom2Size,
2059                       TErr* theErr)
2060     {
2061       theEntity = EEntiteMaillage(-1);
2062       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
2063
2064       if(theErr){
2065         if(theEntityInfo.empty())
2066           *theErr = -1;
2067         if(*theErr < 0)
2068           return -1;
2069       }else if(theEntityInfo.empty()) 
2070         EXCEPTION(std::runtime_error,"GetNbTimeStamps - There is no any Entity on the Mesh");
2071       
2072       bool anIsPerformAdditionalCheck = GetNbMeshes() > 1;
2073
2074       theGeom2Size.clear();
2075       TInt aNbTimeStamps = 0;
2076       TIdt anId = myFile->Id();
2077
2078       MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
2079       TValueHolder<TString, char> aFieldName(anInfo.myName);
2080       MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo;
2081
2082       // workaround for IPAL13676
2083       MED::TEntityInfo localEntityInfo = theEntityInfo;
2084       TEntityInfo::iterator anLocalIter = localEntityInfo.find(eMAILLE);
2085       if(anLocalIter != localEntityInfo.end()){
2086         localEntityInfo[eNOEUD_ELEMENT] = anLocalIter->second;
2087       }
2088         
2089       TEntityInfo::const_iterator anIter = localEntityInfo.begin();
2090       for(; anIter != localEntityInfo.end(); anIter++){
2091         med_entity_type anEntity = med_entity_type(anIter->first);
2092         const TGeom2Size& aGeom2Size = anIter->second;
2093         TGeom2Size::const_iterator anGeomIter = aGeom2Size.begin();
2094         for(; anGeomIter != aGeom2Size.end(); anGeomIter++){
2095           med_geometry_type aGeom = med_geometry_type(anGeomIter->first);
2096           char aMeshName[MED_NAME_SIZE+1];
2097           med_bool islocal;
2098           med_field_type ft;
2099           char dtunit[MED_SNAME_SIZE+1];
2100           med_int myNbComp = MEDfieldnComponentByName(anId,&aFieldName);
2101           char *cname=new char[myNbComp*MED_SNAME_SIZE+1];
2102           char *unitname=new char[myNbComp*MED_SNAME_SIZE+1];
2103           TInt aNbStamps;
2104           MEDfieldInfoByName(anId,
2105                              &aFieldName,
2106                              aMeshName,
2107                              &islocal,
2108                              &ft,
2109                              cname,
2110                              unitname,
2111                              dtunit,
2112                              &aNbStamps);
2113           delete [] cname;
2114           delete [] unitname;
2115           med_int nval = 0;
2116           med_int aNumDt;
2117           med_int aNumOrd;
2118           med_float aDt;
2119           if (aNbStamps > 0)
2120             {
2121               MEDfieldComputingStepInfo(anId,
2122                                         &aFieldName,
2123                                         1,
2124                                         &aNumDt,
2125                                         &aNumOrd,
2126                                         &aDt);
2127               char profilename[MED_NAME_SIZE+1];
2128               char locname[MED_NAME_SIZE+1];
2129               med_int profilsize;
2130               med_int aNbGauss;
2131
2132               // protection from crash (division by zero)
2133               // inside MEDfieldnValueWithProfile function
2134               // caused by the workaround for IPAL13676 (see above)
2135               if( anEntity == MED_NODE_ELEMENT && aGeom % 100 == 0 )
2136                 continue;
2137
2138               nval = MEDfieldnValueWithProfile(anId,
2139                                                &aFieldName,
2140                                                aNumDt,
2141                                                aNumOrd,
2142                                                anEntity,
2143                                                med_geometry_type(aGeom),
2144                                                1,
2145                                                MED_COMPACT_STMODE,
2146                                                profilename,
2147                                                &profilsize,
2148                                                locname,
2149                                                &aNbGauss);
2150             }
2151           bool anIsSatisfied =(nval > 0);
2152           if(anIsSatisfied){
2153             INITMSG(MYDEBUG,
2154                     "GetNbTimeStamps aNbTimeStamps = "<<aNbStamps<<
2155                     "; aGeom = "<<aGeom<<"; anEntity = "<<anEntity<<"\n");
2156             if(anIsPerformAdditionalCheck){
2157               anIsSatisfied = !strcmp(&aMeshName[0],&aMeshInfo.myName[0]);
2158               if(!anIsSatisfied){
2159                 INITMSG(MYDEBUG,
2160                         "GetNbTimeStamps aMeshName = '"<<&aMeshName[0]<<"' != "<<
2161                         "; aMeshInfo.myName = '"<<&aMeshInfo.myName[0]<<"'\n");
2162               }
2163             }
2164           }
2165           if(anIsSatisfied){
2166             theGeom2Size[EGeometrieElement(aGeom)] = anGeomIter->second;
2167             theEntity = EEntiteMaillage(anEntity);
2168             aNbTimeStamps = aNbStamps;
2169           }
2170         }
2171         if(!theGeom2Size.empty()) 
2172           break;
2173       }
2174       return aNbTimeStamps;
2175     }
2176     
2177     //----------------------------------------------------------------------------
2178     void
2179     TVWrapper
2180     ::GetTimeStampInfo(TInt theTimeStampId, 
2181                        MED::TTimeStampInfo& theInfo,
2182                        TErr* theErr)
2183     {
2184       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
2185       
2186       const TGeom2Size& aGeom2Size = theInfo.myGeom2Size;
2187       
2188       if(theErr){
2189         if(aGeom2Size.empty())
2190           *theErr = -1;
2191         if(*theErr < 0)
2192           return;
2193       }else if(aGeom2Size.empty())
2194         EXCEPTION(std::runtime_error,"GetTimeStampInfo - There is no any cell");
2195       
2196       MED::TFieldInfo& aFieldInfo = *theInfo.myFieldInfo;
2197       MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
2198       
2199       TValueHolder<TString, char> aFieldName(aFieldInfo.myName);
2200       TValueHolder<EEntiteMaillage, med_entity_type> anEntity(theInfo.myEntity);
2201       TValueHolder<TInt, med_int> aNumDt(theInfo.myNumDt);
2202       TValueHolder<TInt, med_int> aNumOrd(theInfo.myNumOrd);
2203       TValueHolder<TString, char> anUnitDt(theInfo.myUnitDt);
2204       TValueHolder<TFloat, med_float> aDt(theInfo.myDt);
2205       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
2206       TValueHolder<EBooleen, med_bool> anIsLocal(aFieldInfo.myIsLocal);
2207       TValueHolder<TInt, med_int> aNbRef(aFieldInfo.myNbRef);
2208
2209       TGeom2NbGauss& aGeom2NbGauss = theInfo.myGeom2NbGauss;
2210
2211       // just to get a time stamp unit (anUnitDt)
2212       med_field_type aFieldType;
2213       med_int aNbComp = MEDfieldnComponentByName(myFile->Id(), &aFieldName);
2214       char *aCompName = new char[aNbComp*MED_SNAME_SIZE+1];
2215       char *aCompUnit = new char[aNbComp*MED_SNAME_SIZE+1];
2216       TInt aNbStamps;
2217       MEDfieldInfoByName(myFile->Id(),
2218                          &aFieldName,
2219                          &aMeshName,
2220                          &anIsLocal,
2221                          &aFieldType,
2222                          aCompName,
2223                          aCompUnit,
2224                          &anUnitDt,
2225                          &aNbStamps);
2226       delete [] aCompName;
2227       delete [] aCompUnit;
2228
2229       TGeom2Size::const_iterator anIter = aGeom2Size.begin();
2230       for(; anIter != aGeom2Size.end(); anIter++){
2231         const EGeometrieElement& aGeom = anIter->first;
2232         med_int aNbGauss = -1;
2233
2234         TErr aRet;
2235         aRet = MEDfieldComputingStepInfo(myFile->Id(),
2236                                          &aFieldName,
2237                                          theTimeStampId,
2238                                          &aNumDt,  
2239                                          &aNumOrd,
2240                                          &aDt);
2241         char profilename[MED_NAME_SIZE+1];
2242         med_int profilsize;
2243         char locname[MED_NAME_SIZE+1];
2244         MEDfieldnValueWithProfile(myFile->Id(),
2245                                   &aFieldName,
2246                                   aNumDt,
2247                                   aNumOrd,
2248                                   anEntity,
2249                                   med_geometry_type(aGeom),
2250                                   1,
2251                                   MED_COMPACT_STMODE,
2252                                   profilename,
2253                                   &profilsize,
2254                                   locname,
2255                                   &aNbGauss);
2256
2257         static TInt MAX_NB_GAUSS_POINTS = 32;
2258         if(aNbGauss <= 0 || aNbGauss > MAX_NB_GAUSS_POINTS)
2259           aNbGauss = 1;
2260
2261         aGeom2NbGauss[aGeom] = aNbGauss;
2262
2263         if(theErr) 
2264           *theErr = aRet;
2265         else if(aRet < 0)
2266           EXCEPTION(std::runtime_error,"GetTimeStampInfo - MEDfieldnValueWithProfile(...)");
2267       }      
2268     }
2269
2270     //----------------------------------------------------------------------------
2271     void 
2272     TVWrapper
2273     ::GetTimeStampValue(const PTimeStampValueBase& theTimeStampValue,
2274                         const TMKey2Profile& theMKey2Profile,
2275                         const TKey2Gauss& theKey2Gauss,
2276                         TErr* theErr)
2277     {
2278       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
2279       
2280       if(theErr && *theErr < 0)
2281         return;
2282       
2283       TIdt anId = myFile->Id();
2284       
2285       TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theTimeStampValue->myModeSwitch);
2286       MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile;
2287
2288       MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo;
2289       TValueHolder<EEntiteMaillage, med_entity_type> anEntity(aTimeStampInfo->myEntity);
2290       TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt);
2291       TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd);
2292
2293       MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo;
2294       TValueHolder<TString, char> aFieldName(aFieldInfo->myName);
2295       TValueHolder<EBooleen, med_bool> anIsLocal(aFieldInfo->myIsLocal);
2296
2297       MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo;
2298       TValueHolder<TString, char> aMeshName(aMeshInfo->myName);
2299       
2300       TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->myGeom2Gauss;
2301       TVector<char> aGaussName(GetNOMLength()+1);
2302
2303       med_storage_mode aProfileMode = med_storage_mode(boost::get<0>(theMKey2Profile));
2304       MED::TKey2Profile aKey2Profile = boost::get<1>(theMKey2Profile);
2305       TVector<char> aProfileName(GetNOMLength()+1);
2306
2307       TGeom2Size& aGeom2Size = aTimeStampInfo->myGeom2Size;
2308       TGeom2Size::iterator anIter = aGeom2Size.begin();
2309       for(; anIter != aGeom2Size.end(); anIter++){
2310         EGeometrieElement aGeom = anIter->first;
2311         TInt aNbElem = anIter->second;
2312         med_int profilesize,aNbGauss;
2313
2314         TInt aNbVal = MEDfieldnValueWithProfile(anId,
2315                                                 &aFieldName,
2316                                                 aNumDt,
2317                                                 aNumOrd,
2318                                                 anEntity,
2319                                                 med_geometry_type(aGeom),
2320                                                 1,
2321                                                 aProfileMode,
2322                                                 &aProfileName[0],
2323                                                 &profilesize,
2324                                                 &aGaussName[0],
2325                                                 &aNbGauss);
2326
2327         if(aNbVal <= 0){
2328           if(theErr){
2329             *theErr = -1;
2330             return;
2331           }
2332           EXCEPTION(std::runtime_error,"GetTimeStampValue - MEDfieldnValueWithProfile(...) - aNbVal == "<<aNbVal<<" <= 0");
2333         }
2334         
2335         TInt aNbComp = aFieldInfo->myNbComp;
2336         TInt aNbValue = aNbVal;// / aNbGauss; rules in MED changed
2337         theTimeStampValue->AllocateValue(aGeom,
2338                                          aNbValue,
2339                                          aNbGauss,
2340                                          aNbComp);
2341         TInt aValueSize = theTimeStampValue->GetValueSize(aGeom);
2342
2343         INITMSG(MYDEBUG,
2344                 "TVWrapper::GetTimeStampValue - aGeom = "<<aGeom<<
2345                 "; aNbVal = "<<aNbVal<<
2346                 "; aNbValue = "<<aNbValue<<
2347                 "; aNbGauss = "<<aNbGauss<<
2348                 "; aNbComp = "<<aNbComp<<
2349                 std::endl);
2350         
2351         TErr aRet = MEDfieldValueWithProfileRd(anId,
2352                                                &aFieldName,
2353                                                aNumDt,
2354                                                aNumOrd,
2355                                                anEntity,
2356                                                med_geometry_type(aGeom),
2357                                                aProfileMode,
2358                                                &aProfileName[0],
2359                                                aModeSwitch,
2360                                                MED_ALL_CONSTITUENT,
2361                                                theTimeStampValue->GetValuePtr(aGeom));
2362         if(aRet < 0){
2363           if(theErr){
2364             *theErr = MED_FALSE;
2365             return;
2366           }
2367           EXCEPTION(std::runtime_error,"GetTimeStampValue - MEDfieldValueWithProfileRd(...)");
2368         }
2369
2370         MED::PGaussInfo aGaussInfo;
2371         TGaussInfo::TKey aKey(aGeom,&aGaussName[0]);
2372         if(strcmp(&aGaussName[0],"") != 0){
2373           MED::TKey2Gauss::const_iterator anIter = theKey2Gauss.find(aKey);
2374           if(anIter != theKey2Gauss.end()){
2375             aGaussInfo = anIter->second;
2376             aGeom2Gauss[aGeom] = aGaussInfo;
2377           }
2378         }
2379         
2380         MED::PProfileInfo aProfileInfo;
2381         if(strcmp(&aProfileName[0],MED_NO_PROFILE) != 0){
2382           MED::TKey2Profile::const_iterator anIter = aKey2Profile.find(&aProfileName[0]);
2383           if(anIter != aKey2Profile.end()){
2384             aProfileInfo = anIter->second;
2385             aGeom2Profile[aGeom] = aProfileInfo;
2386           }
2387         }
2388
2389         if(aGaussInfo && aNbGauss != aGaussInfo->GetNbGauss()){
2390           if(theErr){
2391             *theErr = MED_FALSE;
2392             return;
2393           }
2394           EXCEPTION(std::runtime_error,"GetTimeStampValue - aNbGauss != aGaussInfo->GetNbGauss()");
2395         }
2396         
2397         if(aProfileInfo && aProfileInfo->IsPresent()){
2398           TInt aNbSubElem = aProfileInfo->GetSize();
2399           TInt aProfileSize = aNbSubElem*aNbComp*aNbGauss;
2400           if(aProfileSize != aValueSize){
2401             if(theErr){
2402               *theErr = -1;
2403               return;
2404             }
2405             EXCEPTION(std::runtime_error,
2406                       "GetTimeStampValue - aProfileSize("<<aProfileSize<<
2407                       ") != aValueSize("<<aValueSize<<
2408                       "); aNbVal = "<<aNbVal<<
2409                       "; anEntity = "<<anEntity<<
2410                       "; aGeom = "<<aGeom<<
2411                       "; aNbElem = "<<aNbElem<<
2412                       "; aNbSubElem = "<<aNbSubElem<<
2413                       "; aNbComp = "<<aNbComp<<
2414                       "; aNbGauss = "<<aNbGauss<<
2415                       "");
2416           }
2417         }else{
2418           if((aProfileMode == MED_GLOBAL_STMODE) && (aNbElem != aNbValue)){
2419             if(theErr){
2420               *theErr = -1;
2421               return;
2422             }
2423             EXCEPTION(std::runtime_error,
2424                       "GetTimeStampValue - aNbElem("<<aNbElem<<
2425                       ") != aNbValue("<<aNbValue<<
2426                       "); aNbVal = "<<aNbVal<<
2427                       "; anEntity = "<<anEntity<<
2428                       "; aGeom = "<<aGeom<<
2429                       "; aNbElem = "<<aNbElem<<
2430                       "; aNbComp = "<<aNbComp<<
2431                       "; aNbGauss = "<<aNbGauss<<
2432                       "");
2433           }
2434         }
2435       }
2436     }
2437     
2438     //----------------------------------------------------------------------------
2439     void
2440     TVWrapper
2441     ::SetTimeStampValue(const MED::PTimeStampValueBase& theTimeStampValue,
2442                         EModeAcces theMode,
2443                         TErr* theErr)
2444     {
2445       TFileWrapper aFileWrapper(myFile,theMode,theErr);
2446       
2447       if(theErr && *theErr < 0)
2448         return;
2449       
2450       TErr aRet;
2451       TIdt anId = myFile->Id();
2452       
2453       TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theTimeStampValue->myModeSwitch);
2454       MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile;
2455
2456       MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo;
2457       TValueHolder<EEntiteMaillage, med_entity_type> anEntity(aTimeStampInfo->myEntity);
2458       TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt);
2459       TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd);
2460       TValueHolder<TString, char> anUnitDt(aTimeStampInfo->myUnitDt);
2461       TValueHolder<TFloat, med_float> aDt(aTimeStampInfo->myDt);
2462       MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->myGeom2Gauss;
2463
2464       MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo;
2465       TValueHolder<TString, char> aFieldName(aFieldInfo->myName);
2466
2467       MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo;
2468       TValueHolder<TString, char> aMeshName(aMeshInfo->myName);
2469       
2470       const TGeomSet& aGeomSet = theTimeStampValue->myGeomSet;
2471       TGeomSet::const_iterator anIter = aGeomSet.begin();
2472       for(; anIter != aGeomSet.end(); anIter++){
2473         EGeometrieElement aGeom = *anIter;
2474
2475         TVector<char> aGaussName(GetNOMLength()+1);
2476         MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aGeom);
2477         if(aGaussIter != aGeom2Gauss.end()){
2478           MED::PGaussInfo aGaussInfo = aGaussIter->second;
2479           strcpy(&aGaussName[0],&aGaussInfo->myName[0]);
2480         }
2481
2482         TVector<char> aProfileName(GetNOMLength()+1);
2483         med_storage_mode aProfileMode = med_storage_mode(eNO_PFLMOD);
2484         MED::TGeom2Profile::const_iterator aProfileIter = aGeom2Profile.find(aGeom);
2485         if(aProfileIter != aGeom2Profile.end()){
2486           MED::PProfileInfo aProfileInfo = aProfileIter->second;
2487           aProfileMode = med_storage_mode(aProfileInfo->myMode);
2488           strcpy(&aProfileName[0],&aProfileInfo->myName[0]);
2489         }
2490
2491         med_int aNbVal = theTimeStampValue->GetNbVal(aGeom);
2492
2493         aRet = MEDfieldValueWithProfileWr(anId,
2494                                           &aFieldName,
2495                                           aNumDt,
2496                                           aNumOrd,
2497                                           aDt,
2498                                           anEntity,
2499                                           med_geometry_type(aGeom),
2500                                           aProfileMode,
2501                                           &aProfileName[0],
2502                                           &aGaussName[0],
2503                                           aModeSwitch,
2504                                           MED_ALL_CONSTITUENT,
2505                                           aNbVal,
2506                                           theTimeStampValue->GetValuePtr(aGeom));
2507         if(aRet < 0){
2508           if(theErr){
2509             *theErr = MED_FALSE;
2510             break;
2511           }
2512           EXCEPTION(std::runtime_error,"SetTimeStampValue - MEDfieldValueWithProfileWr(...)");
2513         }
2514         
2515       }
2516       
2517       INITMSG(MYDEBUG,"TVWrapper::SetTimeStampValue - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
2518     }
2519     
2520     //----------------------------------------------------------------------------
2521     void 
2522     TVWrapper
2523     ::SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue,
2524                         TErr* theErr)
2525     {
2526       TErr aRet;
2527       SetTimeStampValue(theTimeStampValue,eLECTURE_ECRITURE,&aRet);
2528       
2529       if(aRet < 0)
2530         SetTimeStampValue(theTimeStampValue,eLECTURE_AJOUT,&aRet);
2531
2532       if(theErr) 
2533         *theErr = aRet;
2534     }
2535     
2536     //----------------------------------------------------------------------------
2537     void 
2538     TVWrapper
2539     ::SetGrilleInfo(const MED::TGrilleInfo& theInfo,
2540                     TErr* theErr)
2541     {
2542       SetGrilleInfo(theInfo,eLECTURE_ECRITURE,theErr);
2543     }
2544
2545     //----------------------------------------------------------------------------
2546     void 
2547     TVWrapper
2548     ::SetGrilleInfo(const MED::TGrilleInfo& theInfo,
2549                     EModeAcces theMode,
2550                     TErr* theErr)
2551     {
2552       if(theInfo.myMeshInfo->myType != eSTRUCTURE)
2553         return;
2554       TFileWrapper aFileWrapper(myFile,theMode,theErr);
2555       
2556       if(theErr && *theErr < 0)
2557           return;
2558
2559       MED::TGrilleInfo& anInfo = const_cast<MED::TGrilleInfo&>(theInfo);
2560
2561       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
2562       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
2563
2564       TValueHolder<EGrilleType, med_grid_type > aGrilleType(anInfo.myGrilleType);
2565
2566       TErr aRet = 0;
2567       aRet = MEDmeshGridTypeRd(myFile->Id(),
2568                                &aMeshName,
2569                                &aGrilleType);
2570       if(theErr) 
2571         *theErr = aRet;
2572       else if(aRet < 0)
2573         EXCEPTION(std::runtime_error,"SetGrilleInfo - MEDmeshGridTypeRd(...)");
2574       
2575       if(anInfo.myGrilleType == eGRILLE_STANDARD){
2576         TValueHolder<TNodeCoord, med_float> aCoord(anInfo.myCoord);
2577         TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(anInfo.myModeSwitch);
2578         TValueHolder<TString, char> aCoordNames(anInfo.myCoordNames);
2579         TValueHolder<TString, char> aCoordUnits(anInfo.myCoordUnits);
2580         med_int aNbNoeuds = med_int(anInfo.myCoord.size() / aMeshInfo.myDim);
2581         //med_axis_type aRepere = MED_CARTESIAN;
2582
2583         aRet = MEDmeshNodeCoordinateWr(myFile->Id(),
2584                                        &aMeshName,
2585                                        MED_NO_DT,
2586                                        MED_NO_IT,
2587                                        MED_UNDEF_DT,
2588                                        aModeSwitch,
2589                                        aNbNoeuds,
2590                                        &aCoord);
2591
2592         if(aRet < 0)
2593           EXCEPTION(std::runtime_error,"SetGrilleInfo - MEDmeshNodeCoordinateWr(...)");
2594
2595         TValueHolder<TIntVector, med_int> aGrilleStructure(anInfo.myGrilleStructure);
2596         aRet = MEDmeshGridStructWr(myFile->Id(),
2597                                     &aMeshName,
2598                                    MED_NO_DT,
2599                                    MED_NO_IT,
2600                                    MED_UNDEF_DT,
2601                                    &aGrilleStructure);
2602         if(aRet < 0)
2603           EXCEPTION(std::runtime_error,"SetGrilleInfo - MEDmeshGridStructWr(...)");
2604         
2605       } else {
2606         for(med_int aAxis = 0; aAxis < aMeshInfo.myDim; aAxis++){
2607           aRet = MEDmeshGridIndexCoordinateWr(myFile->Id(),
2608                                               &aMeshName,
2609                                               MED_NO_DT,
2610                                               MED_NO_IT,
2611                                               MED_UNDEF_DT,
2612                                               aAxis+1,
2613                                               anInfo.GetIndexes(aAxis).size(),
2614                                               &anInfo.GetIndexes(aAxis)[0]);
2615
2616           if(aRet < 0)
2617             EXCEPTION(std::runtime_error,"SetGrilleInfo - MEDmeshGridIndexCoordinateWr(...)");
2618         }
2619         
2620       }
2621
2622       return;
2623     }
2624
2625     //----------------------------------------------------------------------------
2626     void
2627     TVWrapper
2628     ::GetGrilleInfo(TGrilleInfo& theInfo,
2629                     TErr* theErr)
2630     {
2631       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
2632
2633       if(theErr && *theErr < 0)
2634           return;
2635       
2636       MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
2637       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
2638       EMaillage aMaillageType = aMeshInfo.myType;
2639       
2640       GetGrilleType(aMeshInfo, theInfo.myGrilleType, theErr);
2641       EGrilleType aGrilleType = theInfo.myGrilleType;
2642
2643       TErr aRet = 0;
2644       if(aMaillageType == eSTRUCTURE && aGrilleType == eGRILLE_STANDARD) {
2645         GetGrilleStruct(aMeshInfo, theInfo.myGrilleStructure, theErr);
2646
2647         TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord);
2648         TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
2649         TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames);
2650         TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits);
2651         //med_axis_type aRepere;
2652
2653         aRet = MEDmeshNodeCoordinateRd(myFile->Id(),
2654                                        &aMeshName,
2655                                        MED_NO_DT,
2656                                        MED_NO_IT,
2657                                        aModeSwitch,
2658                                        &aCoord);
2659
2660         if(theErr) 
2661           *theErr = aRet;
2662         else if(aRet < 0)
2663           EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshNodeCoordinateRd(...)");
2664
2665         //TInt aNbNodes = theInfo.GetNbNodes();//GetNbFamilies(aMeshInfo);
2666         TValueHolder<TElemNum, med_int> aFamNumNode(theInfo.myFamNumNode);
2667         
2668         aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
2669                                            &aMeshName,
2670                                            MED_NO_DT,
2671                                            MED_NO_IT,
2672                                            MED_NODE,
2673                                            MED_NO_GEOTYPE,
2674                                            &aFamNumNode);
2675
2676         if(aRet < 0)
2677         {
2678 //            if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
2679               {
2680                 int mySize = (int)theInfo.myFamNumNode.size();
2681                 theInfo.myFamNumNode.clear();
2682                 theInfo.myFamNumNode.resize(mySize,0);
2683                 aRet = 0;
2684               }
2685 //            else
2686 //              EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...)");
2687         }
2688         if(theErr) 
2689           *theErr = aRet;
2690
2691         //============================
2692       }
2693
2694       if(aMaillageType == eSTRUCTURE && aGrilleType != eGRILLE_STANDARD){
2695         ETable aTable = eCOOR_IND1;
2696         for(med_int anAxis = 1; anAxis <= aMeshInfo.myDim; anAxis++){
2697           switch(anAxis){
2698           case 1 :
2699             aTable = eCOOR_IND1;
2700             break;
2701           case 2 :
2702             aTable = eCOOR_IND2;
2703             break;
2704           case 3 :
2705             aTable = eCOOR_IND3;
2706             break;
2707           default :
2708             aRet = -1;
2709           }
2710             
2711           if(theErr) 
2712             *theErr = aRet;
2713           else if(aRet < 0)
2714             EXCEPTION(std::runtime_error,"GetGrilleInfo - anAxis number out of range(...)");
2715           
2716           TInt aNbIndexes = GetNbNodes(aMeshInfo,aTable);
2717           if(aNbIndexes < 0)
2718             EXCEPTION(std::runtime_error,"GetGrilleInfo - Erreur a la lecture de la taille de l'indice");
2719             
2720           TValueHolder<TFloatVector, med_float> anIndexes(theInfo.GetIndexes(anAxis-1));
2721           //TValueHolder<ETable, med_data_type > table(aTable);
2722           //char aCompNames[MED_SNAME_SIZE+1];
2723           //char anUnitNames[MED_SNAME_SIZE+1];
2724           aRet=MEDmeshGridIndexCoordinateRd(myFile->Id(),&aMeshName,
2725                                             MED_NO_DT,MED_NO_IT,
2726                                             anAxis,
2727                                             &anIndexes);
2728
2729           //theInfo.SetCoordName(anAxis-1, aCompNames);
2730           //theInfo.SetCoordUnit(anAxis-1, anUnitNames);
2731           theInfo.SetGrilleStructure(anAxis-1, aNbIndexes);
2732
2733           if(theErr) 
2734             *theErr = aRet;
2735           else if(aRet < 0)
2736             EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDindicesCoordLire(...)");
2737         }
2738       }
2739
2740       EGeometrieElement aGeom = theInfo.GetGeom();
2741       EEntiteMaillage aEntity = theInfo.GetEntity();
2742       TInt aNbCells = theInfo.GetNbCells();
2743       
2744       theInfo.myFamNum.resize(aNbCells);
2745       TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
2746       
2747       aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
2748                                          &aMeshName,MED_NO_DT,MED_NO_IT,med_entity_type(aEntity),
2749                                          med_geometry_type(aGeom),&aFamNum);
2750
2751       if ( aMeshInfo.myDim == 3 )
2752       {
2753         aGeom = theInfo.GetSubGeom();
2754         aEntity = theInfo.GetSubEntity();
2755         aNbCells = theInfo.GetNbSubCells();
2756       
2757         theInfo.myFamSubNum.resize(aNbCells,0);
2758         TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamSubNum);
2759       
2760         aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
2761                                     &aMeshName,MED_NO_DT,MED_NO_IT,
2762                                     med_entity_type(aEntity),
2763                                     med_geometry_type(aGeom),&aFamNum);
2764       }
2765       if(aRet < 0)
2766       {
2767 //          if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
2768             {
2769               int mySize = (int)theInfo.myFamNumNode.size();
2770               theInfo.myFamNumNode.clear();
2771               theInfo.myFamNumNode.resize(mySize,0);
2772               aRet = 0;
2773             }
2774 //          else
2775 //            EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...)");
2776       }
2777       if(theErr) 
2778         *theErr = aRet;
2779     }
2780
2781     void
2782     TVWrapper
2783     ::GetGrilleType(const MED::TMeshInfo& theMeshInfo,
2784                     EGrilleType& theGridType,
2785                     TErr* theErr)
2786     {
2787       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
2788
2789       if(theErr && *theErr < 0)
2790         EXCEPTION(std::runtime_error," GetGrilleType - aFileWrapper (...)");
2791
2792       MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
2793       
2794       if(aMeshInfo.myType == eSTRUCTURE){
2795         TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
2796         TValueHolder<EGrilleType, med_grid_type> aGridType(theGridType);
2797         TErr aRet = MEDmeshGridTypeRd(myFile->Id(),
2798                                       &aMeshName,
2799                                       &aGridType);
2800
2801         if(aRet < 0)
2802           EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshGridTypeRd(...)");
2803       }
2804     }    
2805     
2806     void
2807     TVWrapper
2808     ::GetGrilleStruct(const MED::TMeshInfo& theMeshInfo,
2809                       TIntVector& theStruct,
2810                       TErr* theErr)
2811     {
2812       TFileWrapper aFileWrapper(myFile,eLECTURE,theErr);
2813       
2814       if(theErr && *theErr < 0)
2815           return;
2816       
2817       TErr aRet;
2818       MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
2819
2820       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
2821       TValueHolder<TIntVector, med_int> aGridStructure(theStruct);
2822         
2823       aRet = MEDmeshGridStructRd(myFile->Id(),
2824                                  &aMeshName,
2825                                  MED_NO_DT,
2826                                  MED_NO_IT,
2827                                  &aGridStructure);
2828       if(theErr) 
2829         *theErr = aRet;
2830       else if(aRet < 0)
2831         EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshGridStructRd(...)");
2832     }
2833   }
2834 }