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