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