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