Salome HOME
Merge 'master' branch into 'V9_dev' branch.
[modules/smesh.git] / src / MEDWrapper / MED_Wrapper.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "MED_Wrapper.hxx"
24 #include "MED_TStructures.hxx"
25 #include "MED_Utilities.hxx"
26
27 #include <med.h>
28 #include <med_err.h>
29
30 #include <boost/version.hpp>
31
32 #ifdef _DEBUG_
33 static int MYDEBUG = 0;
34 static int MYVALUEDEBUG = 0;
35 #else
36 static int MYDEBUG = 0;
37 static int MYVALUEDEBUG = 0;
38 #endif
39
40 namespace MED
41 {
42   //---------------------------------------------------------------
43   TLockProxy
44   ::TLockProxy(TWrapper* theWrapper):
45     myWrapper(theWrapper)
46   {
47 #if BOOST_VERSION >= 103500
48     myWrapper->myMutex.lock();
49 #else
50     boost::detail::thread::lock_ops<TWrapper::TMutex>::lock(myWrapper->myMutex);
51 #endif
52     INITMSG(MYDEBUG, "TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<std::endl);
53   }
54
55   TLockProxy
56   ::~TLockProxy()
57   {
58     INITMSG(MYDEBUG, "~TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<std::endl);
59 #if BOOST_VERSION >= 103500
60     myWrapper->myMutex.unlock();
61 #else
62     boost::detail::thread::lock_ops<TWrapper::TMutex>::unlock(myWrapper->myMutex);
63 #endif
64   }
65
66   TWrapper*
67   TLockProxy
68   ::operator->() const // never throws
69   {
70     return myWrapper;
71   }
72
73   //---------------------------------------------------------------
74   class TFile
75   {
76     TFile();
77     TFile(const TFile&);
78
79   public:
80     TFile(const std::string& theFileName):
81       myCount(0),
82       myFid(0),
83       myFileName(theFileName)
84     {}
85
86     ~TFile()
87     {
88       Close();
89     }
90
91     void
92     Open(EModeAcces theMode,
93          TErr* theErr = NULL)
94     {
95       if (myCount++ == 0) {
96         const char* aFileName = myFileName.c_str();
97         myFid = MEDfileOpen(aFileName, med_access_mode(theMode));
98       }
99       if (theErr)
100         *theErr = TErr(myFid);
101       else if (myFid < 0)
102         EXCEPTION(std::runtime_error, "TFile - MEDfileOpen('"<<myFileName<<"',"<<theMode<<")");
103     }
104
105     const TIdt&
106     Id() const
107     {
108       if (myFid < 0)
109         EXCEPTION(std::runtime_error, "TFile - GetFid() < 0");
110       return myFid;
111     }
112
113     void
114     Close()
115     {
116       if (--myCount == 0)
117         MEDfileClose(myFid);
118     }
119
120   protected:
121     TInt myCount;
122     TIdt myFid;
123     std::string myFileName;
124   };
125
126   //---------------------------------------------------------------
127   class TFileWrapper
128   {
129     PFile myFile;
130
131   public:
132     TFileWrapper(const PFile& theFile,
133                  EModeAcces theMode,
134                  TErr* theErr = NULL):
135       myFile(theFile)
136     {
137       myFile->Open(theMode, theErr);
138     }
139
140     ~TFileWrapper()
141     {
142       myFile->Close();
143     }
144   };
145
146   //----------------------------------------------------------------------------
147   template<class TimeStampValueType>
148   void
149   Print(SharedPtr<TimeStampValueType> theTimeStampValue)
150   {
151     INITMSG(MYDEBUG,"Print - TimeStampValue\n");
152     typename TimeStampValueType::TTGeom2Value& aGeom2Value = theTimeStampValue->myGeom2Value;
153     typename TimeStampValueType::TTGeom2Value::const_iterator anIter = aGeom2Value.begin();
154     for (; anIter != aGeom2Value.end(); anIter++) {
155       const EGeometrieElement& aGeom = anIter->first;
156       const typename TimeStampValueType::TTMeshValue& aMeshValue = anIter->second;
157       TInt aNbElem = aMeshValue.myNbElem;
158       TInt aNbGauss = aMeshValue.myNbGauss;
159       TInt aNbComp = aMeshValue.myNbComp;
160       INITMSG(MYDEBUG, "aGeom = "<<aGeom<<" - "<<aNbElem<<": ");
161       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
162         typename TimeStampValueType::TTMeshValue::TCValueSliceArr aValueSliceArr =
163           aMeshValue.GetGaussValueSliceArr(iElem);
164         ADDMSG(MYVALUEDEBUG, "{");
165         for (TInt iGauss = 0; iGauss < aNbGauss; iGauss++) {
166           const typename TimeStampValueType::TTMeshValue::TCValueSlice& aValueSlice =
167             aValueSliceArr[iGauss];
168           for (TInt iComp = 0; iComp < aNbComp; iComp++) {
169             ADDMSG(MYVALUEDEBUG, aValueSlice[iComp]<<" ");
170           }
171           ADDMSG(MYVALUEDEBUG, "| ");
172         }
173         ADDMSG(MYVALUEDEBUG, "} ");
174       }
175       ADDMSG(MYDEBUG, "\n");
176     }
177   }
178
179   //---------------------------------------------------------------
180   TWrapper
181   ::TWrapper(const std::string& theFileName):
182     myFile(new TFile(theFileName))
183   {
184     TErr aRet;
185     myFile->Open(eLECTURE_ECRITURE, &aRet);
186     // if (aRet < 0)
187     //   myFile->Close();
188     //   myFile->Open(eLECTURE_AJOUT, &aRet);
189     // }
190     if (aRet < 0) {
191       myFile->Close();
192       myFile->Open(eLECTURE, &aRet);
193     }
194     if (aRet < 0) {
195       myFile->Close();
196       myFile->Open(eCREATION, &aRet);
197     }
198   }
199
200   //----------------------------------------------------------------------------
201   TWrapper::
202   ~TWrapper()
203   {
204   }
205
206   //----------------------------------------------------------------------------
207   TInt
208   TWrapper
209   ::GetNbMeshes(TErr* theErr)
210   {
211     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
212
213     if (theErr && *theErr < 0)
214       return -1;
215
216     return MEDnMesh(myFile->Id());
217   }
218
219   //----------------------------------------------------------------------------
220   void
221   TWrapper
222   ::GetMeshInfo(TInt theMeshId,
223                 MED::TMeshInfo& theInfo,
224                 TErr* theErr)
225   {
226     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
227
228     if (theErr && *theErr < 0)
229       return;
230
231     TValueHolder<TString, char> aMeshName(theInfo.myName);
232     TValueHolder<TInt, med_int> aDim(theInfo.myDim);
233     TValueHolder<TInt, med_int> aSpaceDim(theInfo.mySpaceDim);
234     TValueHolder<EMaillage, med_mesh_type> aType(theInfo.myType);
235     char dtunit[MED_SNAME_SIZE+1];
236     med_sorting_type sorttype;
237     med_int nstep;
238     med_axis_type at;
239     int naxis = MEDmeshnAxis(myFile->Id(), theMeshId);
240     char *axisname = new char[naxis*MED_SNAME_SIZE+1];
241     char *axisunit = new char[naxis*MED_SNAME_SIZE+1];
242     TErr aRet = MEDmeshInfo(myFile->Id(),
243                             theMeshId,
244                             &aMeshName,
245                             &aSpaceDim,
246                             &aDim,
247                             &aType,
248                             &theInfo.myDesc[0],
249                             dtunit,
250                             &sorttype,
251                             &nstep,
252                             &at,
253                             axisname,
254                             axisunit);
255     delete [] axisname;
256     delete [] axisunit;
257     if (aRet < 0)
258       EXCEPTION(std::runtime_error, "GetMeshInfo - MEDmeshInfo(...)");
259   }
260
261   //----------------------------------------------------------------------------
262   void
263   TWrapper
264   ::SetMeshInfo(const MED::TMeshInfo& theInfo,
265                 TErr* theErr)
266   {
267     TErr aRet;
268     SetMeshInfo(theInfo, eLECTURE_ECRITURE, &aRet);
269
270     if (aRet < 0)
271       SetMeshInfo(theInfo, eLECTURE_AJOUT, &aRet);
272
273     if (aRet < 0)
274       SetMeshInfo(theInfo, eCREATION, &aRet);
275
276     if (theErr)
277       *theErr = aRet;
278   }
279
280   //----------------------------------------------------------------------------
281   void
282   TWrapper
283   ::SetMeshInfo(const MED::TMeshInfo& theInfo,
284                 EModeAcces theMode,
285                 TErr* theErr)
286   {
287     TFileWrapper aFileWrapper(myFile, theMode, theErr);
288
289     if (theErr && *theErr < 0)
290       return;
291
292     MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
293
294     TValueHolder<TString, char> aMeshName(anInfo.myName);
295     TValueHolder<TInt, med_int> aDim(anInfo.myDim);
296     TValueHolder<TInt, med_int> aSpaceDim(anInfo.mySpaceDim);
297     TValueHolder<EMaillage, med_mesh_type> aType(anInfo.myType);
298     TValueHolder<TString, char> aDesc(anInfo.myDesc);
299
300     char *nam = new char[aSpaceDim*MED_SNAME_SIZE+1];
301     std::fill(nam, nam+aSpaceDim*MED_SNAME_SIZE+1, '\0');
302     char *unit = new char[aSpaceDim*MED_SNAME_SIZE+1];
303     std::fill(unit, unit+aSpaceDim*MED_SNAME_SIZE+1, '\0');
304     TErr aRet = MEDmeshCr(myFile->Id(),
305                           &aMeshName,
306                           aSpaceDim,
307                           aDim,
308                           aType,
309                           &aDesc,
310                           "",
311                           MED_SORT_DTIT,
312                           MED_CARTESIAN,
313                           nam,
314                           unit);
315     delete [] nam;
316     delete [] unit;
317
318     //if (aRet == 0)
319     //  aRet = MEDunvCr(myFile->Id(),&aMeshName);
320
321     INITMSG(MYDEBUG, "TWrapper::SetMeshInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
322
323     if (theErr)
324       *theErr = aRet;
325     else if (aRet < 0)
326       EXCEPTION(std::runtime_error, "SetMeshInfo - MEDmeshCr(...)");
327   }
328
329   //----------------------------------------------------------------------------
330   PMeshInfo
331   TWrapper
332   ::CrMeshInfo(TInt theDim,
333                TInt theSpaceDim,
334                const std::string& theValue,
335                EMaillage theType,
336                const std::string& theDesc)
337   {
338     return PMeshInfo(new TTMeshInfo
339                      (theDim,
340                       theSpaceDim,
341                       theValue,
342                       theType,
343                       theDesc));
344   }
345
346   //----------------------------------------------------------------------------
347   PMeshInfo
348   TWrapper
349   ::CrMeshInfo(const PMeshInfo& theInfo)
350   {
351     return PMeshInfo(new TTMeshInfo(theInfo));
352   }
353
354   //----------------------------------------------------------------------------
355   PMeshInfo
356   TWrapper
357   ::GetPMeshInfo(TInt theId,
358                  TErr* theErr)
359   {
360     PMeshInfo anInfo = CrMeshInfo();
361     GetMeshInfo(theId, *anInfo, theErr);
362     return anInfo;
363   }
364
365   //----------------------------------------------------------------------------
366   TInt
367   TWrapper
368   ::GetNbFamilies(const MED::TMeshInfo& theInfo,
369                   TErr* theErr)
370   {
371     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
372
373     if (theErr && *theErr < 0)
374       return -1;
375
376     MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
377     TValueHolder<TString, char> aName(anInfo.myName);
378     return MEDnFamily(myFile->Id(), &aName);
379   }
380
381   //----------------------------------------------------------------------------
382   TInt
383   TWrapper
384   ::GetNbFamAttr(TInt theFamId,
385                  const MED::TMeshInfo& theInfo,
386                  TErr* theErr)
387   {
388     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
389
390     if (theErr && *theErr < 0)
391       return -1;
392
393     MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
394
395     TValueHolder<TString, char> aName(anInfo.myName);
396
397     return MEDnFamily23Attribute(myFile->Id(), &aName, theFamId);
398   }
399
400   //----------------------------------------------------------------------------
401   TInt
402   TWrapper
403   ::GetNbFamGroup(TInt theFamId,
404                   const MED::TMeshInfo& theInfo,
405                   TErr* theErr)
406   {
407     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
408
409     if (theErr && *theErr < 0)
410       return -1;
411
412     MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
413
414     TValueHolder<TString, char> aName(anInfo.myName);
415
416     return MEDnFamilyGroup(myFile->Id(), &aName, theFamId);
417   }
418
419   //----------------------------------------------------------------------------
420   void
421   TWrapper
422   ::GetFamilyInfo(TInt theFamId,
423                   MED::TFamilyInfo& theInfo,
424                   TErr* theErr)
425   {
426     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
427
428     if (theErr && *theErr < 0)
429       return;
430
431     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
432
433     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
434     TValueHolder<TString, char> aFamilyName(theInfo.myName);
435     TValueHolder<TInt, med_int> aFamilyId(theInfo.myId);
436     TValueHolder<TFamAttr, med_int> anAttrId(theInfo.myAttrId);
437     TValueHolder<TFamAttr, med_int> anAttrVal(theInfo.myAttrVal);
438     TValueHolder<TString, char> anAttrDesc(theInfo.myAttrDesc);
439     TValueHolder<TString, char> aGroupNames(theInfo.myGroupNames);
440
441     TErr aRet = MEDfamily23Info(myFile->Id(),
442                                 &aMeshName,
443                                 theFamId,
444                                 &aFamilyName,
445                                 &anAttrId,
446                                 &anAttrVal,
447                                 &anAttrDesc,
448                                 &aFamilyId,
449                                 &aGroupNames);
450
451     if (theErr)
452       *theErr = aRet;
453     else if (aRet < 0)
454       EXCEPTION(std::runtime_error, "GetFamilyInfo - MEDfamily23Info(...) - "<<
455                 " aMeshInfo.myName = '"<<&aMeshName<<
456                 "'; theFamId = "<<theFamId<<
457                 "; theInfo.myNbGroup = "<<theInfo.myNbGroup<<
458                 "; theInfo.myNbAttr = "<<theInfo.myNbAttr);
459   }
460
461   //----------------------------------------------------------------------------
462   void
463   TWrapper
464   ::SetFamilyInfo(const MED::TFamilyInfo& theInfo,
465                   TErr* theErr)
466   {
467     TErr aRet;
468     SetFamilyInfo(theInfo, eLECTURE_ECRITURE, &aRet);
469
470     if (aRet < 0)
471       SetFamilyInfo(theInfo, eLECTURE_AJOUT, &aRet);
472
473     if (theErr)
474       *theErr = aRet;
475   }
476
477   //----------------------------------------------------------------------------
478   void
479   TWrapper
480   ::SetFamilyInfo(const MED::TFamilyInfo& theInfo,
481                   EModeAcces theMode,
482                   TErr* theErr)
483   {
484     TFileWrapper aFileWrapper(myFile, theMode, theErr);
485
486     if (theErr && *theErr < 0)
487       return;
488
489     MED::TFamilyInfo& anInfo = const_cast<MED::TFamilyInfo&>(theInfo);
490     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
491
492     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
493     TValueHolder<TString, char> aFamilyName(anInfo.myName);
494     TValueHolder<TInt, med_int> aFamilyId(anInfo.myId);
495     TValueHolder<TFamAttr, med_int> anAttrId(anInfo.myAttrId);
496     TValueHolder<TFamAttr, med_int> anAttrVal(anInfo.myAttrVal);
497     TValueHolder<TInt, med_int> aNbAttr(anInfo.myNbAttr);
498     TValueHolder<TString, char> anAttrDesc(anInfo.myAttrDesc);
499     TValueHolder<TInt, med_int> aNbGroup(anInfo.myNbGroup);
500     TValueHolder<TString, char> aGroupNames(anInfo.myGroupNames);
501
502     TErr aRet = MEDfamilyCr(myFile->Id(),
503                             &aMeshName,
504                             &aFamilyName,
505                             aFamilyId,
506                             aNbGroup,
507                             &aGroupNames);
508
509     INITMSG(MYDEBUG, "TWrapper::SetFamilyInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
510
511     if (theErr)
512       *theErr = aRet;
513     else if (aRet < 0)
514       EXCEPTION(std::runtime_error, "SetFamilyInfo - MEDfamilyCr(...)");
515   }
516
517   //----------------------------------------------------------------------------
518   PFamilyInfo
519   TWrapper
520   ::CrFamilyInfo(const PMeshInfo& theMeshInfo,
521                  TInt theNbGroup,
522                  TInt theNbAttr,
523                  TInt theId,
524                  const std::string& theValue)
525   {
526     return PFamilyInfo(new TTFamilyInfo
527                        (theMeshInfo,
528                         theNbGroup,
529                         theNbAttr,
530                         theId,
531                         theValue));
532   }
533
534   //----------------------------------------------------------------------------
535   PFamilyInfo
536   TWrapper
537   ::CrFamilyInfo(const PMeshInfo& theMeshInfo,
538                  const std::string& theValue,
539                  TInt theId,
540                  const MED::TStringSet& theGroupNames,
541                  const MED::TStringVector& theAttrDescs,
542                  const MED::TIntVector& theAttrIds,
543                  const MED::TIntVector& theAttrVals)
544   {
545     return PFamilyInfo(new TTFamilyInfo
546                        (theMeshInfo,
547                         theValue,
548                         theId,
549                         theGroupNames,
550                         theAttrDescs,
551                         theAttrIds,
552                         theAttrVals));
553   }
554
555   //----------------------------------------------------------------------------
556   PFamilyInfo
557   TWrapper
558   ::CrFamilyInfo(const PMeshInfo& theMeshInfo,
559                  const PFamilyInfo& theInfo)
560   {
561     return PFamilyInfo(new TTFamilyInfo
562                        (theMeshInfo,
563                         theInfo));
564   }
565
566   //----------------------------------------------------------------------------
567   PFamilyInfo
568   TWrapper
569   ::GetPFamilyInfo(const PMeshInfo& theMeshInfo,
570                    TInt theId,
571                    TErr* theErr)
572   {
573     // must be reimplemented in connection with mesh type eSTRUCTURE
574     //     if (theMeshInfo->GetType() != eNON_STRUCTURE)
575     //       return PFamilyInfo();
576
577     TInt aNbAttr = GetNbFamAttr(theId, *theMeshInfo);
578     TInt aNbGroup = GetNbFamGroup(theId, *theMeshInfo);
579     PFamilyInfo anInfo = CrFamilyInfo(theMeshInfo, aNbGroup, aNbAttr);
580     GetFamilyInfo(theId, *anInfo, theErr);
581
582 #ifdef _DEBUG_
583     std::string aName = anInfo->GetName();
584     INITMSG(MYDEBUG, "GetPFamilyInfo - aFamilyName = '"<<aName<<
585             "'; andId = "<<anInfo->GetId()<<
586             "; aNbAttr = "<<aNbAttr<<
587             "; aNbGroup = "<<aNbGroup<<"\n");
588     for (TInt iGroup = 0; iGroup < aNbGroup; iGroup++) {
589       aName = anInfo->GetGroupName(iGroup);
590       INITMSG(MYDEBUG, "aGroupName = '"<<aName<<"'\n");
591     }
592 #endif
593
594     return anInfo;
595   }
596
597   //----------------------------------------------------------------------------
598   void
599   TWrapper
600   ::GetNames(TElemInfo& theInfo,
601              TInt theNb,
602              EEntiteMaillage theEntity,
603              EGeometrieElement theGeom,
604              TErr* theErr)
605   {
606     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
607
608     if (theErr && *theErr < 0)
609       return;
610
611     if (theGeom == eBALL)
612       theGeom = GetBallGeom(theInfo.myMeshInfo);
613
614     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
615
616     TValueHolder<TString, char>                        aMeshName  (aMeshInfo.myName);
617     TValueHolder<TString, char>                        anElemNames(theInfo.myElemNames);
618     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity   (theEntity);
619     TValueHolder<EGeometrieElement, med_geometry_type> aGeom      (theGeom);
620
621     TErr aRet = MEDmeshEntityNameRd(myFile->Id(),
622                                     &aMeshName,
623                                     MED_NO_DT,
624                                     MED_NO_IT,
625                                     anEntity,
626                                     aGeom,
627                                     &anElemNames);
628
629     theInfo.myIsElemNames = aRet != 0? eFAUX : eVRAI ;
630
631     if (theErr)
632       *theErr = aRet;
633   }
634
635   //----------------------------------------------------------------------------
636   void
637   TWrapper
638   ::SetNames(const TElemInfo& theInfo,
639              EEntiteMaillage theEntity,
640              EGeometrieElement theGeom,
641              TErr* theErr)
642   {
643     SetNames(theInfo, eLECTURE_ECRITURE, theEntity, theGeom, theErr);
644   }
645
646   //----------------------------------------------------------------------------
647   void
648   TWrapper
649   ::SetNames(const TElemInfo& theInfo,
650              EModeAcces theMode,
651              EEntiteMaillage theEntity,
652              EGeometrieElement theGeom,
653              TErr* theErr)
654   {
655     TFileWrapper aFileWrapper(myFile, theMode, theErr);
656
657     if (theErr && *theErr < 0)
658       return;
659
660     if (theGeom == eBALL)
661       theGeom = GetBallGeom(theInfo.myMeshInfo);
662
663     MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
664     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
665
666     TErr aRet = 0;
667     if (theInfo.myIsElemNames) {
668       TValueHolder<TString, char>                        aMeshName  (aMeshInfo.myName);
669       TValueHolder<TString, char>                        anElemNames(anInfo.myElemNames);
670       TValueHolder<EEntiteMaillage, med_entity_type>     anEntity   (theEntity);
671       TValueHolder<EGeometrieElement, med_geometry_type> aGeom      (theGeom);
672
673       aRet = MEDmeshEntityNameWr(myFile->Id(),
674                                  &aMeshName,
675                                  MED_NO_DT,
676                                  MED_NO_IT,
677                                  anEntity,
678                                   aGeom,
679                                  (TInt)anInfo.myElemNames->size(),
680                                  &anElemNames);
681       if (theErr)
682         *theErr = aRet;
683       else if (aRet < 0)
684         EXCEPTION(std::runtime_error, "SetNames - MEDmeshEntityNameWr(...)");
685     }
686   }
687
688   //----------------------------------------------------------------------------
689   void
690   TWrapper
691   ::GetNumeration(TElemInfo& theInfo,
692                   TInt theNb,
693                   EEntiteMaillage theEntity,
694                   EGeometrieElement theGeom,
695                   TErr* theErr)
696   {
697     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
698
699     if (theErr && *theErr < 0)
700       return;
701
702     if (theGeom == eBALL)
703       theGeom = GetBallGeom(theInfo.myMeshInfo);
704
705     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
706
707     TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
708     TValueHolder<TElemNum, med_int>                    anElemNum(theInfo.myElemNum);
709     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
710     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
711
712     TErr aRet = MEDmeshEntityNumberRd(myFile->Id(),
713                                       &aMeshName,
714                                       MED_NO_DT,
715                                       MED_NO_IT,
716                                       anEntity,
717                                       aGeom,
718                                       &anElemNum);
719
720     theInfo.myIsElemNum = aRet != 0? eFAUX : eVRAI;
721
722     if (theErr)
723       *theErr = aRet;
724   }
725
726   //----------------------------------------------------------------------------
727   void
728   TWrapper
729   ::SetNumeration(const TElemInfo& theInfo,
730                   EEntiteMaillage theEntity,
731                   EGeometrieElement theGeom,
732                   TErr* theErr)
733   {
734     SetNumeration(theInfo, eLECTURE_ECRITURE, theEntity, theGeom, theErr);
735   }
736
737   //----------------------------------------------------------------------------
738   void
739   TWrapper
740   ::SetNumeration(const TElemInfo& theInfo,
741                   EModeAcces theMode,
742                   EEntiteMaillage theEntity,
743                   EGeometrieElement theGeom,
744                   TErr* theErr)
745   {
746     TFileWrapper aFileWrapper(myFile, theMode, theErr);
747
748     if (theErr && *theErr < 0)
749       return;
750
751     if (theGeom == eBALL)
752       theGeom = GetBallGeom(theInfo.myMeshInfo);
753
754     MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
755     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
756
757     TErr aRet = 0;
758     if (theInfo.myIsElemNum) {
759       TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
760       TValueHolder<TElemNum, med_int>                    anElemNum(anInfo.myElemNum);
761       TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
762       TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
763
764       aRet = MEDmeshEntityNumberWr(myFile->Id(),
765                                    &aMeshName,
766                                    MED_NO_DT,
767                                    MED_NO_IT,
768                                    anEntity,
769                                    aGeom,
770                                    (TInt)anInfo.myElemNum->size(),
771                                    &anElemNum);
772       if (theErr)
773         *theErr = aRet;
774       else if (aRet < 0)
775         EXCEPTION(std::runtime_error, "SetNumeration - MEDmeshEntityNumberWr(...)");
776     }
777   }
778
779   //----------------------------------------------------------------------------
780   void
781   TWrapper
782   ::GetFamilies(TElemInfo& theInfo,
783                 TInt theNb,
784                 EEntiteMaillage theEntity,
785                 EGeometrieElement theGeom,
786                 TErr* theErr)
787   {
788     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
789
790     if (theErr && *theErr < 0)
791       return;
792
793     if (theGeom == eBALL)
794       theGeom = GetBallGeom(theInfo.myMeshInfo);
795
796     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
797
798     TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
799     TValueHolder<TElemNum, med_int>                    aFamNum  (theInfo.myFamNum);
800     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
801     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
802
803     TErr aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
804                                             &aMeshName,
805                                             MED_NO_DT,
806                                             MED_NO_IT,
807                                             anEntity,
808                                             aGeom,
809                                             &aFamNum);
810
811     if (aRet < 0) {
812       //        if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
813       {
814         int aSize = (int)theInfo.myFamNum->size();
815         theInfo.myFamNum->clear();
816         theInfo.myFamNum->resize(aSize,0);
817         aRet = 0;
818       }
819       //        else
820       //          EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...) of CELLS");
821     }
822     if (theErr)
823       *theErr = aRet;
824   }
825
826   //----------------------------------------------------------------------------
827   void
828   TWrapper
829   ::SetFamilies(const TElemInfo& theInfo,
830                 EEntiteMaillage theEntity,
831                 EGeometrieElement theGeom,
832                 TErr* theErr)
833   {
834     SetFamilies(theInfo, eLECTURE_ECRITURE, theEntity, theGeom, theErr);
835   }
836
837   //----------------------------------------------------------------------------
838   void
839   TWrapper
840   ::SetFamilies(const TElemInfo& theInfo,
841                 EModeAcces theMode,
842                 EEntiteMaillage theEntity,
843                 EGeometrieElement theGeom,
844                 TErr* theErr)
845   {
846     TFileWrapper aFileWrapper(myFile, theMode, theErr);
847
848     if (theErr && *theErr < 0)
849       return;
850
851     if (theGeom == eBALL)
852       theGeom = GetBallGeom(theInfo.myMeshInfo);
853
854     MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
855     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
856
857     TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
858     TValueHolder<TElemNum, med_int>                    aFamNum  (anInfo.myFamNum);
859     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
860     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
861
862     TErr aRet = MEDmeshEntityFamilyNumberWr(myFile->Id(),
863                                             &aMeshName,
864                                             MED_NO_DT,
865                                             MED_NO_IT,
866                                             anEntity,
867                                             aGeom,
868                                             (TInt)anInfo.myFamNum->size(),
869                                             &aFamNum);
870
871     if (theErr)
872       *theErr = aRet;
873     else if (aRet < 0)
874       EXCEPTION(std::runtime_error, "SetFamilies - MEDmeshEntityFamilyNumberWr(...)");
875   }
876
877   //----------------------------------------------------------------------------
878   TInt
879   TWrapper
880   ::GetNbNodes(const MED::TMeshInfo& theMeshInfo,
881                TErr* theErr)
882   {
883     return GetNbNodes(theMeshInfo, eCOOR, theErr);
884   }
885
886   //----------------------------------------------------------------------------
887   TInt
888   TWrapper
889   ::GetNbNodes(const MED::TMeshInfo& theMeshInfo,
890                ETable theTable,
891                TErr* theErr)
892   {
893     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
894
895     if (theErr && *theErr < 0)
896       return -1;
897
898     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
899
900     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
901     TValueHolder<ETable, med_data_type > aTable(theTable);
902     med_bool chgt,trsf;
903     return MEDmeshnEntity(myFile->Id(),
904                           &aMeshName,
905                           MED_NO_DT,
906                           MED_NO_IT,
907                           MED_NODE,
908                           MED_NO_GEOTYPE,
909                           aTable,
910                           MED_NO_CMODE,
911                           &chgt,
912                           &trsf);
913   }
914
915   //----------------------------------------------------------------------------
916   void
917   TWrapper
918   ::GetNodeInfo(MED::TNodeInfo& theInfo,
919                 TErr* theErr)
920   {
921     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
922
923     if (theErr && *theErr < 0)
924       return;
925
926     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
927
928     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
929     TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
930     TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord);
931     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
932     TValueHolder<ERepere, med_axis_type> aSystem(theInfo.mySystem);
933     TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames);
934     TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits);
935     TValueHolder<TString, char> anElemNames(theInfo.myElemNames);
936     //TValueHolder<EBooleen, med_bool> anIsElemNames(theInfo.myIsElemNames);
937     TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum);
938     //TValueHolder<EBooleen, med_bool> anIsElemNum(theInfo.myIsElemNum);
939     TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
940     TValueHolder<TInt, med_int> aNbElem(theInfo.myNbElem);
941
942     TErr aRet = MEDmeshNodeCoordinateRd(myFile->Id(),
943                                         &aMeshName,
944                                         MED_NO_DT,
945                                         MED_NO_IT,
946                                         aModeSwitch,
947                                         &aCoord);
948
949     TErr aRet2 =MEDmeshEntityFamilyNumberRd(myFile->Id(),
950                                             &aMeshName,
951                                             MED_NO_DT,
952                                             MED_NO_IT,
953                                             MED_NODE,
954                                             MED_NO_GEOTYPE,
955                                             &aFamNum);
956     if (aRet2 < 0) {
957       //        if (aRet2 == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
958       {
959         int mySize = (int)theInfo.myFamNum->size();
960         theInfo.myFamNum->clear();
961         theInfo.myFamNum->resize(mySize,0);
962       }
963       //        else
964       //          EXCEPTION(std::runtime_error,"GetNodeInfo - MEDmeshEntityFamilyNumberRd(...)");
965     }
966
967     if (MEDmeshEntityNameRd(myFile->Id(),
968                             &aMeshName,
969                             MED_NO_DT,
970                             MED_NO_IT,
971                             MED_NODE,
972                             MED_NO_GEOTYPE,
973                             &anElemNames) < 0) theInfo.myIsElemNames=eFAUX;
974
975     if (MEDmeshEntityNumberRd(myFile->Id(),
976                               &aMeshName,
977                               MED_NO_DT,
978                               MED_NO_IT,
979                               MED_NODE,
980                               MED_NO_GEOTYPE,
981                               &anElemNum) < 0) theInfo.myIsElemNum=eFAUX;
982
983     if (theErr)
984       *theErr = aRet;
985     else if (aRet < 0)
986       EXCEPTION(std::runtime_error, "GetNodeInfo - MEDmeshNodeCoordinateRd(...)");
987   }
988
989   //----------------------------------------------------------------------------
990   void
991   TWrapper
992   ::SetNodeInfo(const MED::TNodeInfo& theInfo,
993                 TErr* theErr)
994   {
995     TErr aRet;
996     SetNodeInfo(theInfo, eLECTURE_ECRITURE, &aRet);
997
998     if (aRet < 0)
999       SetNodeInfo(theInfo, eLECTURE_AJOUT, &aRet);
1000
1001     if (theErr)
1002       *theErr = aRet;
1003   }
1004
1005   //----------------------------------------------------------------------------
1006   void
1007   TWrapper
1008   ::SetNodeInfo(const MED::TNodeInfo& theInfo,
1009                 EModeAcces theMode,
1010                 TErr* theErr)
1011   {
1012     TFileWrapper aFileWrapper(myFile, theMode, theErr);
1013
1014     if (theErr && *theErr < 0)
1015       return;
1016
1017     MED::TNodeInfo& anInfo = const_cast<MED::TNodeInfo&>(theInfo);
1018     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1019
1020     TValueHolder<TString, char>                aMeshName    (aMeshInfo.myName);
1021     TValueHolder<TNodeCoord, med_float>        aCoord       (anInfo.myCoord);
1022     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch  (anInfo.myModeSwitch);
1023     TValueHolder<ERepere, med_axis_type>       aSystem      (anInfo.mySystem);
1024     TValueHolder<TString, char>                aCoordNames  (anInfo.myCoordNames);
1025     TValueHolder<TString, char>                aCoordUnits  (anInfo.myCoordUnits);
1026     TValueHolder<TString, char>                anElemNames  (anInfo.myElemNames);
1027     TValueHolder<EBooleen, med_bool>           anIsElemNames(anInfo.myIsElemNames);
1028     TValueHolder<TElemNum, med_int>            anElemNum    (anInfo.myElemNum);
1029     TValueHolder<EBooleen, med_bool>           anIsElemNum  (anInfo.myIsElemNum);
1030     TValueHolder<TElemNum, med_int>            aFamNum      (anInfo.myFamNum);
1031     TValueHolder<TInt, med_int>                aNbElem      (anInfo.myNbElem);
1032
1033     TErr aRet = MEDmeshNodeCoordinateWr(myFile->Id(),
1034                                         &aMeshName,
1035                                         MED_NO_DT,
1036                                         MED_NO_IT,
1037                                         MED_NO_DT,
1038                                         aModeSwitch,
1039                                         aNbElem,
1040                                         &aCoord);
1041
1042     MEDmeshEntityFamilyNumberWr(myFile->Id(),
1043                                 &aMeshName,
1044                                 MED_NO_DT,
1045                                 MED_NO_IT,
1046                                 MED_NODE,
1047                                 MED_NO_GEOTYPE,
1048                                 aNbElem,
1049                                 &aFamNum);
1050     if (anIsElemNames)
1051       MEDmeshEntityNameWr(myFile->Id(),
1052                           &aMeshName,
1053                           MED_NO_DT,
1054                           MED_NO_IT,
1055                           MED_NODE,
1056                           MED_NO_GEOTYPE,
1057                           aNbElem,
1058                           &anElemNames);
1059     if (anIsElemNum)
1060       MEDmeshEntityNumberWr(myFile->Id(),
1061                             &aMeshName,
1062                             MED_NO_DT,
1063                             MED_NO_IT,
1064                             MED_NODE,
1065                             MED_NO_GEOTYPE,
1066                             aNbElem,
1067                             &anElemNum);
1068     if (theErr)
1069       *theErr = aRet;
1070     else if (aRet < 0)
1071       EXCEPTION(std::runtime_error, "SetNodeInfo - MEDmeshNodeCoordinateWr(...)");
1072   }
1073
1074   //----------------------------------------------------------------------------
1075   PNodeInfo
1076   TWrapper
1077   ::CrNodeInfo(const PMeshInfo& theMeshInfo,
1078                TInt theNbElem,
1079                EModeSwitch theMode,
1080                ERepere theSystem,
1081                EBooleen theIsElemNum,
1082                EBooleen theIsElemNames)
1083   {
1084     return PNodeInfo(new TTNodeInfo
1085                      (theMeshInfo,
1086                       theNbElem,
1087                       theMode,
1088                       theSystem,
1089                       theIsElemNum,
1090                       theIsElemNames));
1091   }
1092
1093   //----------------------------------------------------------------------------
1094   PNodeInfo
1095   TWrapper
1096   ::CrNodeInfo(const PMeshInfo& theMeshInfo,
1097                const TFloatVector& theNodeCoords,
1098                EModeSwitch theMode,
1099                ERepere theSystem,
1100                const TStringVector& theCoordNames,
1101                const TStringVector& theCoordUnits,
1102                const TIntVector& theFamilyNums,
1103                const TIntVector& theElemNums,
1104                const TStringVector& theElemNames)
1105   {
1106     return PNodeInfo(new TTNodeInfo
1107                      (theMeshInfo,
1108                       theNodeCoords,
1109                       theMode,
1110                       theSystem,
1111                       theCoordNames,
1112                       theCoordUnits,
1113                       theFamilyNums,
1114                       theElemNums,
1115                       theElemNames));
1116   }
1117
1118   //----------------------------------------------------------------------------
1119   PNodeInfo
1120   TWrapper
1121   ::CrNodeInfo(const PMeshInfo& theMeshInfo,
1122                const PNodeInfo& theInfo)
1123   {
1124     return PNodeInfo(new TTNodeInfo
1125                      (theMeshInfo,
1126                       theInfo));
1127   }
1128
1129   //----------------------------------------------------------------------------
1130   PNodeInfo
1131   TWrapper
1132   ::GetPNodeInfo(const PMeshInfo& theMeshInfo,
1133                  TErr* theErr)
1134   {
1135     TInt aNbElems = GetNbNodes(*theMeshInfo);
1136     if (aNbElems == 0) {
1137       return PNodeInfo();
1138     }
1139
1140     PNodeInfo anInfo = CrNodeInfo(theMeshInfo, aNbElems);
1141     GetNodeInfo(*anInfo, theErr);
1142
1143 #ifdef _DEBUG_
1144     TInt aDim = theMeshInfo->myDim;
1145     TInt aNbElem = anInfo->GetNbElem();
1146     INITMSG(MYDEBUG, "GetPNodeInfo: ");
1147     {
1148       INITMSG(MYDEBUG, "aCoords: "<<aNbElem<<": ");
1149       TNodeCoord& aCoord = anInfo->myCoord;
1150       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1151         for (TInt iDim = 0, anId = iElem*aDim; iDim < aDim; iDim++, anId++) {
1152           ADDMSG(MYVALUEDEBUG, aCoord[anId]<<",");
1153         }
1154         ADDMSG(MYVALUEDEBUG, " ");
1155       }
1156       ADDMSG(MYDEBUG, std::endl);
1157
1158       BEGMSG(MYVALUEDEBUG, "GetFamNum: ");
1159       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1160         ADDMSG(MYVALUEDEBUG, anInfo->GetFamNum(iElem)<<", ");
1161       }
1162       ADDMSG(MYVALUEDEBUG, std::endl);
1163
1164       if (anInfo->IsElemNum()) {
1165         BEGMSG(MYVALUEDEBUG, "GetElemNum: ");
1166         for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1167           ADDMSG(MYVALUEDEBUG, anInfo->GetElemNum(iElem)<<", ");
1168         }
1169         ADDMSG(MYVALUEDEBUG, std::endl);
1170       }
1171     }
1172     ADDMSG(MYDEBUG, std::endl);
1173 #endif
1174
1175     return anInfo;
1176   }
1177
1178   //----------------------------------------------------------------------------
1179   PElemInfo
1180   TWrapper
1181   ::CrElemInfo(const PMeshInfo& theMeshInfo,
1182                TInt theNbElem,
1183                EBooleen theIsElemNum,
1184                EBooleen theIsElemNames)
1185   {
1186     return PElemInfo(new TTElemInfo
1187                      (theMeshInfo,
1188                       theNbElem,
1189                       theIsElemNum,
1190                       theIsElemNames));
1191   }
1192
1193   //----------------------------------------------------------------------------
1194   PElemInfo
1195   TWrapper
1196   ::CrElemInfo(const PMeshInfo& theMeshInfo,
1197                TInt theNbElem,
1198                const TIntVector& theFamNum,
1199                const TIntVector& aElemNum,
1200                const TStringVector& aElemNames)
1201   {
1202     return PElemInfo(new TTElemInfo
1203                      (theMeshInfo,
1204                       theNbElem,
1205                       theFamNum,
1206                       aElemNum,
1207                       aElemNames));
1208   }
1209
1210   //----------------------------------------------------------------------------
1211   PElemInfo
1212   TWrapper
1213   ::GetPElemInfo(const PMeshInfo& theMeshInfo,
1214                  EEntiteMaillage theEntity,
1215                  EGeometrieElement theGeom,
1216                  EConnectivite theConnMode,
1217                  TErr* theErr)
1218   {
1219     EMaillage aType = theMeshInfo->GetType();
1220     if (aType == eNON_STRUCTURE) {
1221       switch (theGeom) {
1222       case ePOINT1:
1223         if (theEntity == eNOEUD)
1224           return GetPNodeInfo(theMeshInfo, theErr);
1225         return GetPCellInfo(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1226         break;
1227       case ePOLYGONE:
1228         return GetPPolygoneInfo(theMeshInfo, theEntity, theGeom, theConnMode);
1229         break;
1230       case ePOLYEDRE:
1231         return GetPPolyedreInfo(theMeshInfo, theEntity, theGeom, theConnMode);
1232         break;
1233       default:
1234         return GetPCellInfo(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1235       }
1236     }
1237     else {
1238       PGrilleInfo aGrille = GetPGrilleInfo(theMeshInfo);
1239
1240       TInt nbElems;
1241       EBooleen theIsElemNum = eFAUX;
1242       // nodes
1243       switch (theGeom) {
1244       case ePOINT1:
1245         nbElems = aGrille->GetNbNodes();
1246         theIsElemNum = eVRAI;
1247         break;
1248       case eSEG2:
1249       case eQUAD4:
1250       case eHEXA8:
1251         nbElems = aGrille->GetNbCells();
1252         break;
1253       default:
1254         nbElems = 0;
1255       }
1256
1257       TIntVector aFamNum;
1258       TIntVector aElemNum;
1259       TStringVector aElemNames;
1260
1261       PElemInfo aElemInfo;
1262
1263       if (theGeom == ePOINT1) {
1264         aElemInfo = CrElemInfo(theMeshInfo,
1265                                nbElems,
1266                                theIsElemNum);
1267         MED::TElemInfo &aTElemInfo = *aElemInfo;
1268
1269         // must be reimplemente in connection with mesh type eSTRUCTURE
1270         //      GetNumeration(aTElemInfo,
1271         //                    nbElems,
1272         //                    theEntity,
1273         //                    theGeom,
1274         //                    theErr);
1275
1276         GetFamilies(aTElemInfo,
1277                     nbElems,
1278                     theEntity,
1279                     theGeom,
1280                     theErr);
1281
1282         // must be reimplemente in connection with mesh type eSTRUCTURE
1283         //      GetNames(aTElemInfo,
1284         //               nbElems,
1285         //               theEntity,
1286         //               theGeom,
1287         //               theErr);
1288       }
1289       else {
1290         aElemInfo = CrElemInfo(theMeshInfo,
1291                                nbElems,
1292                                aFamNum,
1293                                aElemNum,
1294                                aElemNames);
1295       }
1296
1297       return aElemInfo;
1298     }
1299     return PElemInfo();
1300   }
1301
1302   //----------------------------------------------------------------------------
1303   TInt
1304   TWrapper
1305   ::GetNbPolygones(const MED::TMeshInfo& theMeshInfo,
1306                    EEntiteMaillage theEntity,
1307                    EGeometrieElement theGeom,
1308                    EConnectivite theConnMode,
1309                    TErr* theErr)
1310   {
1311     return GetNbCells(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1312   }
1313
1314   //----------------------------------------------------------------------------
1315   TInt
1316   TWrapper
1317   ::GetPolygoneConnSize(const MED::TMeshInfo& theMeshInfo,
1318                         EEntiteMaillage theEntity,
1319                         EGeometrieElement theGeom,
1320                         EConnectivite theConnMode,
1321                         TErr* theErr)
1322   {
1323     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
1324
1325     if (theErr && *theErr < 0)
1326       return 0;
1327
1328     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1329
1330     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1331     med_int aTaille = 0;
1332     med_bool chgt,trsf;
1333     aTaille=MEDmeshnEntity(myFile->Id(),
1334                            &aMeshName,
1335                            MED_NO_DT,
1336                            MED_NO_IT,
1337                            med_entity_type(theEntity),
1338                            med_geometry_type(theGeom),
1339                            MED_CONNECTIVITY,
1340                            med_connectivity_mode(theConnMode),
1341                            &chgt,
1342                            &trsf);
1343
1344     if (aTaille < 0)
1345       EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshnEntity(...)");
1346
1347     return TInt(aTaille);
1348   }
1349
1350   //-----------------------------------------------------------------
1351   void
1352   TWrapper
1353   ::GetPolygoneInfo(MED::TPolygoneInfo& theInfo,
1354                     TErr* theErr)
1355   {
1356     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
1357
1358     if (theErr && *theErr < 0)
1359       return;
1360
1361     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
1362
1363     TValueHolder<TString, char                       > aMeshName(aMeshInfo.myName);
1364     TValueHolder<TElemNum, med_int                   > anIndex  (theInfo.myIndex);
1365     TValueHolder<TElemNum, med_int                   > aConn    (theInfo.myConn);
1366     TValueHolder<EEntiteMaillage, med_entity_type    > anEntity (theInfo.myEntity);
1367     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theInfo.myGeom);
1368     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theInfo.myConnMode);
1369     TInt aNbElem = (TInt)theInfo.myElemNum->size();
1370
1371     TErr aRet;
1372     aRet = MEDmeshPolygon2Rd(myFile->Id(), &aMeshName,
1373                              MED_NO_DT, MED_NO_IT,
1374                              anEntity, aGeom,
1375                              aConnMode, &anIndex, &aConn);
1376
1377     if (theErr)
1378       *theErr = aRet;
1379     else if (aRet < 0)
1380       EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshPolygonRd(...)");
1381
1382     if (theInfo.myIsElemNames) {
1383       GetNames(theInfo, aNbElem, theInfo.myEntity, theInfo.myGeom, &aRet);
1384       if (theErr)
1385         *theErr = aRet;
1386     }
1387
1388     if (theInfo.myIsElemNum) {
1389       GetNumeration(theInfo, aNbElem, theInfo.myEntity, theInfo.myGeom, &aRet);
1390       if (theErr)
1391         *theErr = aRet;
1392     }
1393
1394     GetFamilies(theInfo, aNbElem, theInfo.myEntity, theInfo.myGeom, &aRet);
1395     if (theErr)
1396       *theErr = aRet;
1397   }
1398
1399   //----------------------------------------------------------------------------
1400   void
1401   TWrapper
1402   ::SetPolygoneInfo(const MED::TPolygoneInfo& theInfo,
1403                     TErr* theErr)
1404   {
1405     SetPolygoneInfo(theInfo, eLECTURE_ECRITURE, theErr);
1406   }
1407
1408   //----------------------------------------------------------------------------
1409   void
1410   TWrapper
1411   ::SetPolygoneInfo(const MED::TPolygoneInfo& theInfo,
1412                     EModeAcces theMode,
1413                     TErr* theErr)
1414   {
1415     TFileWrapper aFileWrapper(myFile, theMode, theErr);
1416
1417     if (theErr && *theErr < 0)
1418       return;
1419
1420     MED::TPolygoneInfo& anInfo = const_cast<MED::TPolygoneInfo&>(theInfo);
1421     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1422
1423     TValueHolder<TString, char                       > aMeshName(aMeshInfo.myName);
1424     TValueHolder<TElemNum, med_int                   > anIndex  (anInfo.myIndex);
1425     TValueHolder<TElemNum, med_int                   > aConn    (anInfo.myConn);
1426     TValueHolder<EEntiteMaillage, med_entity_type    > anEntity (anInfo.myEntity);
1427     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (anInfo.myGeom);
1428     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(anInfo.myConnMode);
1429
1430     TErr aRet = MEDmeshPolygon2Wr(myFile->Id(), &aMeshName,
1431                                   MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
1432                                   anEntity, aGeom,
1433                                   aConnMode, anInfo.myNbElem + 1,
1434                                   &anIndex, &aConn);
1435     if (theErr)
1436       *theErr = aRet;
1437     else if (aRet < 0)
1438       EXCEPTION(std::runtime_error, "SetPolygoneInfo - MEDmeshPolygonWr(...)");
1439
1440     SetNames(anInfo, theInfo.myEntity, anInfo.myGeom, &aRet);
1441     if (theErr)
1442       *theErr = aRet;
1443
1444     SetNumeration(anInfo, theInfo.myEntity, anInfo.myGeom, &aRet);
1445     if (theErr)
1446       *theErr = aRet;
1447
1448     SetFamilies(anInfo, theInfo.myEntity, anInfo.myGeom, &aRet);
1449     if (theErr)
1450       *theErr = aRet;
1451   }
1452
1453   //----------------------------------------------------------------------------
1454   PPolygoneInfo
1455   TWrapper
1456   ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
1457                    EEntiteMaillage theEntity,
1458                    EGeometrieElement theGeom,
1459                    TInt theNbElem,
1460                    TInt theConnSize,
1461                    EConnectivite theConnMode,
1462                    EBooleen theIsElemNum,
1463                    EBooleen theIsElemNames)
1464   {
1465     return PPolygoneInfo(new TTPolygoneInfo
1466                          (theMeshInfo,
1467                           theEntity,
1468                           theGeom,
1469                           theNbElem,
1470                           theConnSize,
1471                           theConnMode,
1472                           theIsElemNum,
1473                           theIsElemNames));
1474   }
1475
1476   //----------------------------------------------------------------------------
1477   PPolygoneInfo
1478   TWrapper
1479   ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
1480                    EEntiteMaillage theEntity,
1481                    EGeometrieElement theGeom,
1482                    const TIntVector& theIndexes,
1483                    const TIntVector& theConnectivities,
1484                    EConnectivite theConnMode,
1485                    const TIntVector& theFamilyNums,
1486                    const TIntVector& theElemNums,
1487                    const TStringVector& theElemNames)
1488   {
1489     return PPolygoneInfo(new TTPolygoneInfo
1490                          (theMeshInfo,
1491                           theEntity,
1492                           theGeom,
1493                           theIndexes,
1494                           theConnectivities,
1495                           theConnMode,
1496                           theFamilyNums,
1497                           theElemNums,
1498                           theElemNames));
1499   }
1500
1501   //----------------------------------------------------------------------------
1502   PPolygoneInfo
1503   TWrapper
1504   ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
1505                    const PPolygoneInfo& theInfo)
1506   {
1507     return PPolygoneInfo(new TTPolygoneInfo
1508                          (theMeshInfo,
1509                           theInfo));
1510   }
1511
1512   //----------------------------------------------------------------------------
1513   PPolygoneInfo
1514   TWrapper
1515   ::GetPPolygoneInfo(const PMeshInfo& theMeshInfo,
1516                      EEntiteMaillage theEntity,
1517                      EGeometrieElement theGeom,
1518                      EConnectivite theConnMode)
1519   {
1520     if (theMeshInfo->GetType() != eNON_STRUCTURE)
1521       return PPolygoneInfo();
1522
1523     TInt aNbElem = GetNbPolygones(theMeshInfo, theEntity, theGeom, theConnMode);
1524     TInt aConnSize = GetPolygoneConnSize(theMeshInfo, theEntity, theGeom, theConnMode);
1525     PPolygoneInfo anInfo = CrPolygoneInfo(theMeshInfo, theEntity, theGeom, aNbElem, aConnSize, theConnMode);
1526     GetPolygoneInfo(anInfo);
1527
1528 #ifdef _DEBUG_
1529     INITMSG(MYDEBUG, "GetPPolygoneInfo"<<
1530             " - theGeom = "<<theGeom<<
1531             "; aNbElem = "<<aNbElem<<": ");
1532     for (TInt iElem = 1; iElem < aNbElem; iElem++) {
1533       TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
1534       TInt aConnDim = aConnSlice.size();
1535       for (TInt iConn = 0; iConn < aConnDim; iConn++) {
1536         ADDMSG(MYVALUEDEBUG, aConnSlice[iConn]<<",");
1537       }
1538       ADDMSG(MYDEBUG, " ");
1539     }
1540     ADDMSG(MYDEBUG, std::endl);
1541 #endif
1542
1543     return anInfo;
1544   }
1545
1546   //----------------------------------------------------------------------------
1547   TInt
1548   TWrapper
1549   ::GetNbPolyedres(const MED::TMeshInfo& theMeshInfo,
1550                    EEntiteMaillage theEntity,
1551                    EGeometrieElement theGeom,
1552                    EConnectivite theConnMode,
1553                    TErr* theErr)
1554   {
1555     return GetNbCells(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1556   }
1557
1558   //----------------------------------------------------------------------------
1559   void
1560   TWrapper
1561   ::GetPolyedreConnSize(const TMeshInfo& theMeshInfo,
1562                         TInt& theNbFaces,
1563                         TInt& theConnSize,
1564                         EConnectivite theConnMode,
1565                         TErr* theErr)
1566   {
1567     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
1568
1569     if (theErr && *theErr < 0)
1570       EXCEPTION(std::runtime_error, "GetPolyedreConnSize - (...)");
1571
1572     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1573
1574     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1575     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theConnMode);
1576     //TValueHolder<TInt, med_int> aNbFaces(theNbFaces);
1577     //TValueHolder<TInt, med_int> aConnSize(theConnSize);
1578
1579     med_bool chgt, trsf;
1580     theNbFaces = MEDmeshnEntity(myFile->Id(),
1581                                 &aMeshName,
1582                                 MED_NO_DT,
1583                                 MED_NO_IT,
1584                                 MED_CELL,
1585                                 MED_POLYHEDRON,
1586                                 MED_INDEX_NODE,
1587                                 aConnMode,
1588                                 &chgt,
1589                                 &trsf);
1590
1591     theConnSize = MEDmeshnEntity(myFile->Id(),
1592                                  &aMeshName,
1593                                  MED_NO_DT,
1594                                  MED_NO_IT,
1595                                  MED_CELL,
1596                                  MED_POLYHEDRON,
1597                                  MED_CONNECTIVITY,
1598                                  aConnMode,
1599                                  &chgt,
1600                                  &trsf);
1601
1602     if (theNbFaces < 0 || theConnSize<0)
1603       EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshnEntity(...)");
1604
1605   }
1606
1607   //-----------------------------------------------------------------
1608   void
1609   TWrapper
1610   ::GetPolyedreInfo(TPolyedreInfo& theInfo,
1611                     TErr* theErr)
1612   {
1613     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
1614
1615     if (theErr && *theErr < 0)
1616       return;
1617
1618     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
1619
1620     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1621     TInt aNbElem = (TInt)theInfo.myElemNum->size();
1622     TValueHolder<TElemNum, med_int> anIndex(theInfo.myIndex);
1623     TValueHolder<TElemNum, med_int> aFaces(theInfo.myFaces);
1624     TValueHolder<TElemNum, med_int> aConn(theInfo.myConn);
1625     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theInfo.myConnMode);
1626
1627     TErr aRet;
1628     aRet = MEDmeshPolyhedronRd(myFile->Id(),
1629                                &aMeshName,
1630                                MED_NO_DT,
1631                                MED_NO_IT,
1632                                MED_CELL,
1633                                aConnMode,
1634                                &anIndex,
1635                                &aFaces,
1636                                &aConn);
1637
1638     if (theErr)
1639       *theErr = aRet;
1640     else if (aRet < 0)
1641       EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshPolyhedronRd(...)");
1642
1643     if (theInfo.myIsElemNames) {
1644       GetNames(theInfo, aNbElem, theInfo.myEntity, ePOLYEDRE, &aRet);
1645       if (theErr)
1646         *theErr = aRet;
1647     }
1648
1649     if (theInfo.myIsElemNum) {
1650       GetNumeration(theInfo, aNbElem, theInfo.myEntity, ePOLYEDRE, &aRet);
1651       if (theErr)
1652         *theErr = aRet;
1653     }
1654
1655     GetFamilies(theInfo, aNbElem, theInfo.myEntity, ePOLYEDRE, &aRet);
1656     if (theErr)
1657       *theErr = aRet;
1658   }
1659
1660   //----------------------------------------------------------------------------
1661   void
1662   TWrapper
1663   ::SetPolyedreInfo(const TPolyedreInfo& theInfo,
1664                     TErr* theErr)
1665   {
1666     SetPolyedreInfo(theInfo, eLECTURE_ECRITURE, theErr);
1667   }
1668
1669   //----------------------------------------------------------------------------
1670   void
1671   TWrapper
1672   ::SetPolyedreInfo(const MED::TPolyedreInfo& theInfo,
1673                     EModeAcces theMode,
1674                     TErr* theErr)
1675   {
1676     TFileWrapper aFileWrapper(myFile, theMode, theErr);
1677
1678     if (theErr && *theErr < 0)
1679       return;
1680
1681     MED::TPolyedreInfo& anInfo = const_cast<MED::TPolyedreInfo&>(theInfo);
1682     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1683
1684     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1685     TValueHolder<TElemNum, med_int> anIndex(anInfo.myIndex);
1686     TValueHolder<TElemNum, med_int> aFaces(anInfo.myFaces);
1687     TValueHolder<TElemNum, med_int> aConn(anInfo.myConn);
1688     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(anInfo.myConnMode);
1689
1690     TErr aRet;
1691     aRet = MEDmeshPolyhedronWr(myFile->Id(),
1692                                &aMeshName,
1693                                MED_NO_DT,
1694                                MED_NO_IT,
1695                                MED_UNDEF_DT,
1696                                MED_CELL,
1697                                aConnMode,
1698                                anInfo.myNbElem+1,
1699                                &anIndex,
1700                                (TInt)anInfo.myFaces->size(),
1701                                &aFaces,
1702                                &aConn);
1703
1704     if (theErr)
1705       *theErr = aRet;
1706     else if (aRet < 0)
1707       EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshPolyhedronWr(...)");
1708
1709     TValueHolder<EEntiteMaillage, med_entity_type> anEntity(anInfo.myEntity);
1710
1711     if (theInfo.myIsElemNames) {
1712       TValueHolder<TString, char> anElemNames(anInfo.myElemNames);
1713       aRet = MEDmeshEntityNameWr(myFile->Id(),
1714                                  &aMeshName,
1715                                  MED_NO_DT,
1716                                  MED_NO_IT,
1717                                  anEntity,
1718                                  MED_POLYHEDRON,
1719                                  (TInt)anInfo.myElemNames->size(),
1720                                  &anElemNames);
1721       if (theErr)
1722         *theErr = aRet;
1723       else if (aRet < 0)
1724         EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshEntityNameWr(...)");
1725     }
1726
1727     if (theInfo.myIsElemNum) {
1728       TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
1729       aRet = MEDmeshEntityNumberWr(myFile->Id(),
1730                                    &aMeshName,
1731                                    MED_NO_DT,
1732                                    MED_NO_IT,
1733                                    anEntity,
1734                                    MED_POLYHEDRON,
1735                                    (TInt)anInfo.myElemNum->size(),
1736                                    &anElemNum);
1737       if (theErr)
1738         *theErr = aRet;
1739       else if (aRet < 0)
1740         EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshEntityNumberWr(...)");
1741     }
1742
1743     TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum);
1744     aRet = MEDmeshEntityFamilyNumberWr(myFile->Id(),
1745                                        &aMeshName,
1746                                        MED_NO_DT,
1747                                        MED_NO_IT,
1748                                        anEntity,
1749                                        MED_POLYHEDRON,
1750                                        (TInt)anInfo.myFamNum->size(),
1751                                        &aFamNum);
1752
1753     if (theErr)
1754       *theErr = aRet;
1755     else if (aRet < 0)
1756       EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshEntityFamilyNumberWr(...)");
1757   }
1758
1759   //----------------------------------------------------------------------------
1760   PPolyedreInfo
1761   TWrapper
1762   ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
1763                    EEntiteMaillage theEntity,
1764                    EGeometrieElement theGeom,
1765                    TInt theNbElem,
1766                    TInt theNbFaces,
1767                    TInt theConnSize,
1768                    EConnectivite theConnMode,
1769                    EBooleen theIsElemNum,
1770                    EBooleen theIsElemNames)
1771   {
1772     return PPolyedreInfo(new TTPolyedreInfo
1773                          (theMeshInfo,
1774                           theEntity,
1775                           theGeom,
1776                           theNbElem,
1777                           theNbFaces,
1778                           theConnSize,
1779                           theConnMode,
1780                           theIsElemNum,
1781                           theIsElemNames));
1782   }
1783
1784   //----------------------------------------------------------------------------
1785   PPolyedreInfo
1786   TWrapper
1787   ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
1788                    EEntiteMaillage theEntity,
1789                    EGeometrieElement theGeom,
1790                    const TIntVector& theIndexes,
1791                    const TIntVector& theFaces,
1792                    const TIntVector& theConnectivities,
1793                    EConnectivite theConnMode,
1794                    const TIntVector& theFamilyNums,
1795                    const TIntVector& theElemNums,
1796                    const TStringVector& theElemNames)
1797   {
1798     return PPolyedreInfo(new TTPolyedreInfo
1799                          (theMeshInfo,
1800                           theEntity,
1801                           theGeom,
1802                           theIndexes,
1803                           theFaces,
1804                           theConnectivities,
1805                           theConnMode,
1806                           theFamilyNums,
1807                           theElemNums,
1808                           theElemNames));
1809   }
1810
1811   //----------------------------------------------------------------------------
1812   PPolyedreInfo
1813   TWrapper
1814   ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
1815                    const PPolyedreInfo& theInfo)
1816   {
1817     return PPolyedreInfo(new TTPolyedreInfo
1818                          (theMeshInfo,
1819                           theInfo));
1820   }
1821
1822   //----------------------------------------------------------------------------
1823   PPolyedreInfo
1824   TWrapper
1825   ::GetPPolyedreInfo(const PMeshInfo& theMeshInfo,
1826                      EEntiteMaillage theEntity,
1827                      EGeometrieElement theGeom,
1828                      EConnectivite theConnMode)
1829   {
1830     if (theMeshInfo->GetType() != eNON_STRUCTURE)
1831       return PPolyedreInfo();
1832     TInt aNbElem = GetNbPolyedres(theMeshInfo, theEntity, theGeom, theConnMode);
1833     TInt aNbFaces, aConnSize;
1834     GetPolyedreConnSize(theMeshInfo, aNbFaces, aConnSize, theConnMode);
1835     PPolyedreInfo anInfo = CrPolyedreInfo(theMeshInfo, theEntity, theGeom, aNbElem, aNbFaces, aConnSize, theConnMode);
1836     GetPolyedreInfo(anInfo);
1837
1838 #ifdef _DEBUG_
1839     INITMSG(MYDEBUG, "GetPPolyedreInfo"<<
1840             " - theGeom = "<<theGeom<<
1841             "; aNbElem = "<<aNbElem<<": ");
1842     for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1843       TCConnSliceArr aConnSliceArr = anInfo->GetConnSliceArr(iElem);
1844       TInt aNbFaces = aConnSliceArr.size();
1845       ADDMSG(MYDEBUG, "{");
1846       for (TInt iFace = 0; iFace < aNbFaces; iFace++) {
1847         TCConnSlice aConnSlice = aConnSliceArr[iFace];
1848         TInt aNbConn = aConnSlice.size();
1849         ADDMSG(MYDEBUG, "[");
1850         for (TInt iConn = 0; iConn < aNbConn; iConn++) {
1851           ADDMSG(MYVALUEDEBUG, aConnSlice[iConn]<<",");
1852         }
1853         ADDMSG(MYDEBUG, "] ");
1854       }
1855       ADDMSG(MYDEBUG, "} ");
1856     }
1857     ADDMSG(MYDEBUG, std::endl);
1858 #endif
1859
1860     return anInfo;
1861   }
1862
1863   //-----------------------------------------------------------------
1864   TEntityInfo
1865   TWrapper
1866   ::GetEntityInfo(const MED::TMeshInfo& theMeshInfo,
1867                   EConnectivite theConnMode,
1868                   TErr* theErr)
1869   {
1870     TEntityInfo anInfo;
1871
1872     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
1873
1874     if (theErr && *theErr < 0)
1875       return anInfo;
1876
1877     if (theMeshInfo.GetType() == eNON_STRUCTURE) {
1878       TInt aNbElem = GetNbNodes(theMeshInfo);
1879       if (aNbElem > 0) {
1880         anInfo[eNOEUD][ePOINT1] = aNbElem;
1881         const TEntity2GeomSet& anEntity2GeomSet = GetEntity2GeomSet();
1882         TEntity2GeomSet::const_iterator anIter = anEntity2GeomSet.begin();
1883         TEntity2GeomSet::const_iterator anIterEnd = anEntity2GeomSet.end();
1884         for (; anIter != anIterEnd; anIter++) {
1885           const EEntiteMaillage& anEntity = anIter->first;
1886           const TGeomSet& aGeomSet = anIter->second;
1887           TGeomSet::const_iterator anIter2 = aGeomSet.begin();
1888           TGeomSet::const_iterator anIterEnd2 = aGeomSet.end();
1889           for (; anIter2 != anIterEnd2; anIter2++) {
1890             const EGeometrieElement& aGeom = *anIter2;
1891             aNbElem = GetNbCells(theMeshInfo, anEntity, aGeom, theConnMode, theErr);
1892             if (aNbElem > 0) {
1893               if (anEntity == eSTRUCT_ELEMENT) {
1894                 const TInt nbStructTypes = aNbElem;
1895                 for (TInt structType = 0; structType < nbStructTypes; ++structType) {
1896                   // check type name to keep only "MED_BALL" structured element
1897                   TValueHolder<TString, char> aMeshName((TString&) theMeshInfo.myName);
1898                   char                        geotypename[ MED_NAME_SIZE + 1] = "";
1899                   med_geometry_type           geotype;
1900                   MEDmeshEntityInfo(myFile->Id(), &aMeshName, MED_NO_DT, MED_NO_IT,
1901                                     med_entity_type(anEntity), structType+1,
1902                                     geotypename, &geotype);
1903                   if (strcmp(geotypename, MED_BALL_NAME) == 0) {
1904                     aNbElem = GetNbCells(theMeshInfo, anEntity, EGeometrieElement(geotype),
1905                                          theConnMode, theErr);
1906                     if (aNbElem > 0)
1907                       anInfo[anEntity][EGeometrieElement(geotype)] = aNbElem;
1908                   }
1909                 }
1910               }
1911               else {
1912                 anInfo[anEntity][aGeom] = aNbElem;
1913               }
1914             }
1915           }
1916         }
1917       }
1918     }
1919     else { // eSTRUCTURE
1920       EGrilleType aGrilleType;
1921       TInt aNbNodes = 1;
1922       TInt aNbElem  = 1;
1923       TInt aNbSub   = 0;
1924       TInt aDim = theMeshInfo.GetDim();
1925       EGeometrieElement aGeom, aSubGeom;
1926       EEntiteMaillage aSubEntity = eMAILLE;
1927
1928       GetGrilleType(theMeshInfo, aGrilleType);
1929
1930       TIntVector aStruct(aDim);
1931       if (aGrilleType == eGRILLE_STANDARD)
1932         {
1933           GetGrilleStruct(theMeshInfo, aStruct, theErr);
1934         }
1935       else
1936         { // eGRILLE_CARTESIENNE and eGRILLE_POLAIRE
1937           ETable aTable[3] = { eCOOR_IND1, eCOOR_IND2, eCOOR_IND3 };
1938           for (med_int anAxis = 0; anAxis < aDim; anAxis++)
1939             aStruct[ anAxis ] = GetNbNodes(theMeshInfo, aTable[anAxis]);
1940         }
1941       for (med_int i = 0; i < aDim; i++) {
1942         aNbNodes = aNbNodes * aStruct[i];
1943         aNbElem = aNbElem * (aStruct[i] - 1);
1944       }
1945       switch (aDim) {
1946       case 1:
1947         aGeom = eSEG2;
1948         break;
1949       case 2:
1950         aGeom = eQUAD4;
1951         aSubGeom = eSEG2;
1952         aSubEntity = eARETE;
1953         aNbSub =
1954           (aStruct[0])   * (aStruct[1]-1) +
1955           (aStruct[0]-1) * (aStruct[1]);
1956         break;
1957       case 3:
1958         aGeom = eHEXA8;
1959         aSubGeom = eQUAD4;
1960         aSubEntity = eFACE;
1961         aNbSub =
1962           (aStruct[0])   * (aStruct[1]-1) * (aStruct[2]-1) +
1963           (aStruct[0]-1) * (aStruct[1])   * (aStruct[2]-1) +
1964           (aStruct[0]-1) * (aStruct[1]-1) * (aStruct[2]);
1965         break;
1966       }
1967       anInfo[eNOEUD][ePOINT1] = aNbNodes;
1968       anInfo[eMAILLE][aGeom] = aNbElem;
1969       if (aDim > 1)
1970         anInfo[aSubEntity][aSubGeom] = aNbSub;
1971     }
1972     return anInfo;
1973   }
1974
1975   //-----------------------------------------------------------------
1976   TInt
1977   TWrapper
1978   ::GetNbCells(const MED::TMeshInfo& theMeshInfo,
1979                EEntiteMaillage theEntity,
1980                EGeometrieElement theGeom,
1981                EConnectivite theConnMode,
1982                TErr* theErr)
1983   {
1984     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
1985
1986     if (theErr && *theErr < 0)
1987       return -1;
1988
1989     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1990     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1991     med_bool chgt, trsf;
1992     switch (theGeom)
1993       {
1994       case MED::ePOLYGONE:
1995       case MED::ePOLYGON2:
1996         {
1997           return MEDmeshnEntity(myFile->Id(), &aMeshName,
1998                                 MED_NO_DT, MED_NO_IT,
1999                                 med_entity_type(theEntity), med_geometry_type(theGeom),
2000                                 MED_INDEX_NODE, med_connectivity_mode(theConnMode),
2001                                 &chgt, &trsf)-1;
2002         }
2003       case MED::ePOLYEDRE:
2004         {
2005           return MEDmeshnEntity(myFile->Id(), &aMeshName,
2006                                 MED_NO_DT, MED_NO_IT,
2007                                 med_entity_type(theEntity), MED_POLYHEDRON,
2008                                 MED_INDEX_FACE, med_connectivity_mode(theConnMode),
2009                                 &chgt, &trsf)-1;
2010         }
2011       case MED::eBALL:
2012         {
2013           return GetNbBalls(theMeshInfo);
2014         }
2015       default:
2016         {
2017           return MEDmeshnEntity(myFile->Id(), &aMeshName,
2018                                 MED_NO_DT, MED_NO_IT,
2019                                 med_entity_type(theEntity), med_geometry_type(theGeom),
2020                                 MED_CONNECTIVITY, med_connectivity_mode(theConnMode),
2021                                 &chgt, &trsf);
2022         }
2023       }
2024     return 0;
2025   }
2026
2027   //----------------------------------------------------------------------------
2028   void
2029   TWrapper
2030   ::GetCellInfo(MED::TCellInfo& theInfo,
2031                 TErr* theErr)
2032   {
2033     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
2034
2035     if (theErr && *theErr < 0)
2036       return;
2037
2038     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
2039
2040     TValueHolder<TString, char>                        aMeshName    (aMeshInfo.myName);
2041     TValueHolder<TElemNum, med_int>                    aConn        (theInfo.myConn);
2042     TValueHolder<EModeSwitch, med_switch_mode>         aModeSwitch  (theInfo.myModeSwitch);
2043     TValueHolder<TString, char>                        anElemNames  (theInfo.myElemNames);
2044     TValueHolder<EBooleen, med_bool>                   anIsElemNames(theInfo.myIsElemNames);
2045     TValueHolder<TElemNum, med_int>                    anElemNum    (theInfo.myElemNum);
2046     TValueHolder<EBooleen, med_bool>                   anIsElemNum  (theInfo.myIsElemNum);
2047     TValueHolder<TElemNum, med_int>                    aFamNum      (theInfo.myFamNum);
2048     TValueHolder<EBooleen, med_bool>                   anIsFamNum   (theInfo.myIsFamNum);
2049     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity     (theInfo.myEntity);
2050     TValueHolder<EGeometrieElement, med_geometry_type> aGeom        (theInfo.myGeom);
2051     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode    (theInfo.myConnMode);
2052
2053     TErr aRet;
2054     aRet = MEDmeshElementRd(myFile->Id(),
2055                             &aMeshName,
2056                             MED_NO_DT,
2057                             MED_NO_IT,
2058                             anEntity,
2059                             aGeom,
2060                             aConnMode,
2061                             aModeSwitch,
2062                             &aConn,
2063                             &anIsElemNames,
2064                             &anElemNames,
2065                             &anIsElemNum,
2066                             &anElemNum,
2067                             &anIsFamNum,
2068                             &aFamNum);
2069
2070     if (theErr)
2071       *theErr = aRet;
2072     else if (aRet < 0)
2073       EXCEPTION(std::runtime_error, "GetCellInfo - MEDmeshElementRd(...)");
2074
2075     if (anIsFamNum == MED_FALSE)
2076       {
2077         int mySize = (int) theInfo.myFamNum->size();
2078         theInfo.myFamNum->clear();
2079         theInfo.myFamNum->resize(mySize, 0);
2080       }
2081
2082   }
2083
2084   //----------------------------------------------------------------------------
2085   void
2086   TWrapper
2087   ::SetCellInfo(const MED::TCellInfo& theInfo,
2088                 TErr* theErr)
2089   {
2090     SetCellInfo(theInfo, eLECTURE_ECRITURE, theErr);
2091   }
2092
2093   //----------------------------------------------------------------------------
2094   void
2095   TWrapper
2096   ::SetCellInfo(const MED::TCellInfo& theInfo,
2097                 EModeAcces theMode,
2098                 TErr* theErr)
2099   {
2100     TFileWrapper aFileWrapper(myFile, theMode, theErr);
2101
2102     if (theErr && *theErr < 0)
2103       return;
2104
2105     MED::TCellInfo& anInfo    = const_cast<MED::TCellInfo&>(theInfo);
2106     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
2107
2108     TValueHolder<TString, char>                        aMeshName    (aMeshInfo.myName);
2109     TValueHolder<TElemNum, med_int>                    aConn        (anInfo.myConn);
2110     TValueHolder<EModeSwitch, med_switch_mode>         aModeSwitch  (anInfo.myModeSwitch);
2111     TValueHolder<TString, char>                        anElemNames  (anInfo.myElemNames);
2112     TValueHolder<EBooleen, med_bool>                   anIsElemNames(anInfo.myIsElemNames);
2113     TValueHolder<TElemNum, med_int>                    anElemNum    (anInfo.myElemNum);
2114     TValueHolder<EBooleen, med_bool>                   anIsElemNum  (anInfo.myIsElemNum);
2115     TValueHolder<TElemNum, med_int>                    aFamNum      (anInfo.myFamNum);
2116     TValueHolder<EBooleen, med_bool>                   anIsFamNum   (anInfo.myIsFamNum);
2117     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity     (anInfo.myEntity);
2118     TValueHolder<EGeometrieElement, med_geometry_type> aGeom        (anInfo.myGeom);
2119     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode    (anInfo.myConnMode);
2120     TValueHolder<TInt, med_int>                        aNbElem      (anInfo.myNbElem);
2121
2122     TErr aRet;
2123     aRet = MEDmeshElementConnectivityWr(myFile->Id(),
2124                                         &aMeshName,
2125                                         MED_NO_DT,
2126                                         MED_NO_IT,
2127                                         MED_UNDEF_DT,
2128                                         anEntity,
2129                                         aGeom,
2130                                         aConnMode,
2131                                         aModeSwitch,
2132                                         aNbElem,
2133                                         &aConn);
2134
2135     MEDmeshEntityFamilyNumberWr(myFile->Id(),
2136                                 &aMeshName,
2137                                 MED_NO_DT,
2138                                 MED_NO_IT,
2139                                 anEntity,
2140                                 aGeom,
2141                                 aNbElem,
2142                                 &aFamNum);
2143     if (anIsElemNames)
2144       MEDmeshEntityNameWr(myFile->Id(),
2145                           &aMeshName,
2146                           MED_NO_DT,
2147                           MED_NO_IT,
2148                           anEntity,
2149                           aGeom,
2150                           aNbElem,
2151                           &anElemNames);
2152     if (anIsElemNum)
2153       MEDmeshEntityNumberWr(myFile->Id(),
2154                             &aMeshName,
2155                             MED_NO_DT,
2156                             MED_NO_IT,
2157                             anEntity,
2158                             aGeom,
2159                             aNbElem,
2160                             &anElemNum);
2161     if (theErr)
2162       *theErr = aRet;
2163     else if (aRet < 0)
2164       EXCEPTION(std::runtime_error, "SetCellInfo - MEDmeshElementWr(...)");
2165   }
2166
2167   //----------------------------------------------------------------------------
2168   PCellInfo
2169   TWrapper
2170   ::CrCellInfo(const PMeshInfo& theMeshInfo,
2171                EEntiteMaillage theEntity,
2172                EGeometrieElement theGeom,
2173                TInt theNbElem,
2174                EConnectivite theConnMode,
2175                EBooleen theIsElemNum,
2176                EBooleen theIsElemNames,
2177                EModeSwitch theMode)
2178   {
2179     return PCellInfo(new TTCellInfo
2180                      (theMeshInfo,
2181                       theEntity,
2182                       theGeom,
2183                       theNbElem,
2184                       theConnMode,
2185                       theIsElemNum,
2186                       theIsElemNames,
2187                       theMode));
2188   }
2189
2190   //----------------------------------------------------------------------------
2191   PCellInfo
2192   TWrapper
2193   ::CrCellInfo(const PMeshInfo& theMeshInfo,
2194                EEntiteMaillage theEntity,
2195                EGeometrieElement theGeom,
2196                const TIntVector& theConnectivities,
2197                EConnectivite theConnMode,
2198                const TIntVector& theFamilyNums,
2199                const TIntVector& theElemNums,
2200                const TStringVector& theElemNames,
2201                EModeSwitch theMode)
2202   {
2203     return PCellInfo(new TTCellInfo
2204                      (theMeshInfo,
2205                       theEntity,
2206                       theGeom,
2207                       theConnectivities,
2208                       theConnMode,
2209                       theFamilyNums,
2210                       theElemNums,
2211                       theElemNames,
2212                       theMode));
2213   }
2214
2215   //----------------------------------------------------------------------------
2216   PCellInfo
2217   TWrapper
2218   ::CrCellInfo(const PMeshInfo& theMeshInfo,
2219                const PCellInfo& theInfo)
2220   {
2221     return PCellInfo(new TTCellInfo
2222                      (theMeshInfo,
2223                       theInfo));
2224   }
2225
2226   //----------------------------------------------------------------------------
2227   PCellInfo
2228   TWrapper
2229   ::GetPCellInfo(const PMeshInfo& theMeshInfo,
2230                  EEntiteMaillage theEntity,
2231                  EGeometrieElement theGeom,
2232                  EConnectivite theConnMode,
2233                  TErr* theErr)
2234   {
2235     if (theMeshInfo->GetType() != eNON_STRUCTURE)
2236       return PCellInfo();
2237     TInt aNbElem = GetNbCells(theMeshInfo, theEntity, theGeom, theConnMode);
2238     PCellInfo anInfo = CrCellInfo(theMeshInfo, theEntity, theGeom, aNbElem, theConnMode);
2239     GetCellInfo(anInfo, theErr);
2240
2241 #ifdef _DEBUG_
2242     TInt aConnDim = anInfo->GetConnDim();
2243     INITMSG(MYDEBUG, "GetPCellInfo - theEntity = "<<theEntity<<"; theGeom = "<<theGeom<<"; aConnDim: "<<aConnDim<<"\n");
2244     BEGMSG(MYDEBUG, "GetPCellInfo - aNbElem: "<<aNbElem<<": ");
2245     for (TInt iElem = 0; iElem < aNbElem; iElem++) {
2246       TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
2247       for (TInt iConn = 0; iConn < aConnDim; iConn++) {
2248         ADDMSG(MYVALUEDEBUG, aConnSlice[iConn]<<",");
2249       }
2250       ADDMSG(MYVALUEDEBUG, " ");
2251     }
2252     ADDMSG(MYDEBUG, std::endl);
2253
2254     BEGMSG(MYVALUEDEBUG, "GetPCellInfo - GetFamNum: ");
2255     for (TInt iElem = 0; iElem < aNbElem; iElem++) {
2256       ADDMSG(MYVALUEDEBUG, anInfo->GetFamNum(iElem)<<", ");
2257     }
2258     ADDMSG(MYVALUEDEBUG, std::endl);
2259
2260     if (anInfo->IsElemNum()) {
2261       BEGMSG(MYVALUEDEBUG, "GetPCellInfo - GetElemNum: ");
2262       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
2263         ADDMSG(MYVALUEDEBUG, anInfo->GetElemNum(iElem)<<", ");
2264       }
2265       ADDMSG(MYVALUEDEBUG, std::endl);
2266     }
2267     ADDMSG(MYDEBUG, std::endl);
2268 #endif
2269
2270     return anInfo;
2271   }
2272
2273   //----------------------------------------------------------------------------
2274   EGeometrieElement
2275   TWrapper
2276   ::GetBallGeom(const TMeshInfo& theMeshInfo)
2277   {
2278     TFileWrapper aFileWrapper(myFile, eLECTURE);
2279
2280     // read med_geometry_type of "MED_BALL" element
2281     char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME;
2282     return EGeometrieElement(MEDstructElementGeotype(myFile->Id(), geotypename));
2283   }
2284
2285   //----------------------------------------------------------------------------
2286   TInt
2287   TWrapper
2288   ::GetNbBalls(const TMeshInfo& theMeshInfo)
2289   {
2290     TFileWrapper aFileWrapper(myFile, eLECTURE);
2291
2292     EGeometrieElement ballType = GetBallGeom(theMeshInfo);
2293     if (ballType < 0)
2294       return 0;
2295
2296     return GetNbCells(theMeshInfo, eSTRUCT_ELEMENT, ballType, eNOD);
2297   }
2298
2299   //----------------------------------------------------------------------------
2300   void
2301   TWrapper
2302   ::GetBallInfo(TBallInfo& theInfo,
2303                 TErr* theErr)
2304   {
2305     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
2306
2307     // check geometry of MED_BALL
2308     if (theInfo.myGeom == eBALL)
2309       {
2310         theInfo.myGeom = GetBallGeom(*theInfo.myMeshInfo);
2311         if (theInfo.myGeom < 0) {
2312           if (!theErr)
2313             EXCEPTION(std::runtime_error, "GetBallInfo - no balls in the mesh");
2314           *theErr = theInfo.myGeom;
2315           return;
2316         }
2317       }
2318
2319     // read nodes ids
2320     GetCellInfo(theInfo);
2321
2322     // read diameters
2323     TValueHolder<TString, char>                        aMeshName (theInfo.myMeshInfo->myName);
2324     TValueHolder<EGeometrieElement, med_geometry_type> aGeom     (theInfo.myGeom);
2325     TValueHolder<TFloatVector, void>                   aDiam     (theInfo.myDiameters);
2326     char varattname[ MED_NAME_SIZE + 1] = MED_BALL_DIAMETER;
2327
2328     TErr aRet = MEDmeshStructElementVarAttRd(myFile->Id(), &aMeshName,
2329                                              MED_NO_DT, MED_NO_IT,
2330                                              aGeom,
2331                                              varattname,
2332                                              &aDiam);
2333     if (theErr)
2334       *theErr = aRet;
2335     else if (aRet < 0)
2336       EXCEPTION(std::runtime_error, "GetBallInfo - pb at reading diameters");
2337   }
2338
2339   //----------------------------------------------------------------------------
2340   void
2341   TWrapper
2342   ::SetBallInfo(const TBallInfo& theInfo,
2343                 TErr* theErr)
2344   {
2345     SetBallInfo(theInfo, eLECTURE_ECRITURE, theErr);
2346   }
2347
2348   //----------------------------------------------------------------------------
2349   void
2350   TWrapper
2351   ::SetBallInfo(const TBallInfo& theInfo,
2352                 EModeAcces theMode,
2353                 TErr* theErr)
2354   {
2355     TFileWrapper aFileWrapper(myFile, theMode, theErr);
2356
2357     TErr ret;
2358     char ballsupportname[MED_NAME_SIZE+1] = "BALL_SUPPORT_MESH";
2359     EGeometrieElement ballGeom = GetBallGeom(*theInfo.myMeshInfo);
2360     if (ballGeom < 0)
2361       {
2362         // no ball model in the file, create support mesh for it
2363         char dummyname [MED_NAME_SIZE*3+1] = "";
2364         if ((ret = MEDsupportMeshCr(myFile->Id(),
2365                                     ballsupportname,
2366                                     theInfo.myMeshInfo->GetSpaceDim(),
2367                                     theInfo.myMeshInfo->GetDim(),
2368                                     "Support mesh for a ball model",
2369                                     MED_CARTESIAN,
2370                                     /*axisname=*/dummyname,
2371                                     /*unitname=*/dummyname)) < 0) {
2372           if (!theErr)
2373             EXCEPTION(std::runtime_error, "SetBallInfo - MEDsupportMeshCr");
2374           *theErr = ret;
2375           return;
2376         }
2377         // write coordinates of 1 node
2378         med_float coord[3] = {0, 0, 0};
2379         if ((ret = MEDmeshNodeCoordinateWr(myFile->Id(),
2380                                            ballsupportname, MED_NO_DT, MED_NO_IT, 0.0,
2381                                            MED_FULL_INTERLACE, /*nnode=*/1, coord)) < 0) {
2382           if (!theErr)
2383             EXCEPTION(std::runtime_error, "SetBallInfo - MEDmeshNodeCoordinateWr");
2384           *theErr = ret;
2385           return;
2386         }
2387         // ball model creation
2388         char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME;
2389         if ((ballGeom = (EGeometrieElement) MEDstructElementCr(myFile->Id(),
2390                                                                geotypename,
2391                                                                theInfo.myMeshInfo->GetSpaceDim(),
2392                                                                ballsupportname,
2393                                                                MED_NODE,MED_NONE)) < 0) {
2394           if (!theErr)
2395             EXCEPTION(std::runtime_error, "SetBallInfo - MEDstructElementCr");
2396           *theErr = ret;
2397           return;
2398         }
2399         // create diameter attribute
2400         if ((ret = MEDstructElementVarAttCr(myFile->Id(),
2401                                             geotypename, MED_BALL_DIAMETER,
2402                                             MED_ATT_FLOAT64, /*ncomp=*/1)) < 0) {
2403           if (!theErr)
2404             EXCEPTION(std::runtime_error, "SetBallInfo - MEDstructElementVarAttCr");
2405           *theErr = ret;
2406           return;
2407         }
2408       } // ballGeom < 0
2409
2410     TBallInfo& aBallInfo = ((TBallInfo&) theInfo);
2411     aBallInfo.myGeom = ballGeom;
2412
2413     // write node ids
2414     SetCellInfo(theInfo, theMode, theErr);
2415     if (theErr && theErr < 0)
2416       return;
2417
2418     // write diameter
2419     TValueHolder<TString, char>                        aMeshName (aBallInfo.myMeshInfo->myName);
2420     TValueHolder<EGeometrieElement, med_geometry_type> aGeom     (aBallInfo.myGeom);
2421     TValueHolder<TFloatVector, void>                   aDiam     (aBallInfo.myDiameters);
2422     ret = MEDmeshStructElementVarAttWr(myFile->Id(), &aMeshName,
2423                                        MED_NO_DT, MED_NO_IT,
2424                                        aGeom, MED_BALL_DIAMETER,
2425                                        theInfo.myNbElem, &aDiam);
2426     if (theErr)
2427       *theErr = ret;
2428     else if (ret < 0)
2429       EXCEPTION(std::runtime_error, "SetBallInfo - MEDmeshStructElementVarAttWr");
2430   }
2431
2432   //----------------------------------------------------------------------------
2433   PBallInfo
2434   TWrapper
2435   ::CrBallInfo(const PMeshInfo& theMeshInfo,
2436                TInt theNbBalls,
2437                EBooleen theIsElemNum)
2438   {
2439     return PBallInfo(new TTBallInfo(theMeshInfo, theNbBalls, theIsElemNum));
2440   }
2441
2442   //----------------------------------------------------------------------------
2443   PBallInfo
2444   TWrapper
2445   ::CrBallInfo(const PMeshInfo& theMeshInfo,
2446                const TIntVector& theNodes,
2447                TFloatVector& theDiameters,
2448                const TIntVector& theFamilyNums,
2449                const TIntVector& theElemNums)
2450   {
2451     return PBallInfo(new TTBallInfo(theMeshInfo, theNodes, theDiameters,
2452                                     theFamilyNums, theElemNums));
2453   }
2454
2455   //----------------------------------------------------------------------------
2456   PBallInfo
2457   TWrapper
2458   ::CrBallInfo(const PMeshInfo& theMeshInfo,
2459                const PBallInfo& theInfo)
2460   {
2461     return PBallInfo(new TTBallInfo(theMeshInfo, theInfo));
2462   }
2463
2464   //----------------------------------------------------------------------------
2465   PBallInfo
2466   TWrapper
2467   ::GetPBallInfo(const PMeshInfo& theMeshInfo)
2468   {
2469     TInt nbBalls = GetNbBalls(theMeshInfo);
2470     if (nbBalls < 1) return PBallInfo();
2471
2472     PBallInfo anInfo = CrBallInfo(theMeshInfo, nbBalls);
2473     GetBallInfo(anInfo);
2474
2475     return anInfo;
2476   }
2477
2478   //-----------------------------------------------------------------
2479   TInt
2480   TWrapper
2481   ::GetNbFields(TErr* theErr)
2482   {
2483     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
2484
2485     if (theErr && *theErr < 0)
2486       return -1;
2487
2488     return MEDnField(myFile->Id());
2489   }
2490
2491   //----------------------------------------------------------------------------
2492   TInt
2493   TWrapper
2494   ::GetNbComp(TInt theFieldId,
2495               TErr* theErr)
2496   {
2497     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
2498
2499     if (theErr && *theErr < 0)
2500       return -1;
2501
2502     return MEDfieldnComponent(myFile->Id(), theFieldId);
2503   }
2504
2505   //----------------------------------------------------------------------------
2506   void
2507   TWrapper
2508   ::GetFieldInfo(TInt theFieldId,
2509                  MED::TFieldInfo& theInfo,
2510                  TErr* theErr)
2511   {
2512     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
2513
2514     if (theErr && *theErr < 0)
2515       return;
2516
2517     TString aFieldName(256); // Protect from memory problems with too long names
2518     TValueHolder<ETypeChamp, med_field_type> aType(theInfo.myType);
2519     TValueHolder<TString, char> aCompNames(theInfo.myCompNames);
2520     TValueHolder<TString, char> anUnitNames(theInfo.myUnitNames);
2521     MED::TMeshInfo& aMeshInfo = theInfo.myMeshInfo;
2522
2523     TErr aRet;
2524     med_bool local;
2525     char dtunit[MED_SNAME_SIZE+1];
2526     char local_mesh_name[MED_NAME_SIZE+1]="";
2527     med_int nbofstp;
2528     theInfo.myNbComp = MEDfieldnComponent(myFile->Id(), theFieldId);
2529     aRet = MEDfieldInfo(myFile->Id(),
2530                         theFieldId,
2531                         &aFieldName[0],
2532                         local_mesh_name,
2533                         &local,
2534                         &aType,
2535                         &aCompNames,
2536                         &anUnitNames,
2537                         dtunit,
2538                         &nbofstp);
2539
2540     if (strcmp(&aMeshInfo.myName[0], local_mesh_name) != 0) {
2541       if (theErr)
2542         *theErr = -1;
2543       return;
2544     }
2545
2546     theInfo.SetName(aFieldName);
2547
2548     if (theErr)
2549       *theErr = aRet;
2550     else if (aRet < 0)
2551       EXCEPTION(std::runtime_error, "GetFieldInfo - MEDfieldInfo(...)");
2552   }
2553
2554   //----------------------------------------------------------------------------
2555   void
2556   TWrapper
2557   ::SetFieldInfo(const MED::TFieldInfo& theInfo,
2558                  TErr* theErr)
2559   {
2560     TErr aRet;
2561     SetFieldInfo(theInfo, eLECTURE_ECRITURE, &aRet);
2562
2563     if (aRet < 0)
2564       SetFieldInfo(theInfo, eLECTURE_AJOUT, &aRet);
2565
2566     if (theErr)
2567       *theErr = aRet;
2568   }
2569
2570   //----------------------------------------------------------------------------
2571   void
2572   TWrapper
2573   ::SetFieldInfo(const MED::TFieldInfo& theInfo,
2574                  EModeAcces theMode,
2575                  TErr* theErr)
2576   {
2577     TFileWrapper aFileWrapper(myFile, theMode, theErr);
2578
2579     if (theErr && *theErr < 0)
2580       return;
2581
2582     MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
2583
2584     TValueHolder<TString, char> aFieldName(anInfo.myName);
2585     TValueHolder<ETypeChamp, med_field_type> aType(anInfo.myType);
2586     TValueHolder<TString, char> aCompNames(anInfo.myCompNames);
2587     TValueHolder<TString, char> anUnitNames(anInfo.myUnitNames);
2588     MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo;
2589     TErr aRet;
2590     char dtunit[MED_SNAME_SIZE+1];
2591     std::fill(dtunit, dtunit+MED_SNAME_SIZE+1, '\0');
2592     aRet = MEDfieldCr(myFile->Id(),
2593                       &aFieldName,
2594                       aType,
2595                       anInfo.myNbComp,
2596                       &aCompNames,
2597                       &anUnitNames,
2598                       dtunit,
2599                       &aMeshInfo.myName[0]);
2600     if (theErr)
2601       *theErr = aRet;
2602     else if (aRet < 0)
2603       EXCEPTION(std::runtime_error, "SetFieldInfo - MEDfieldCr(...)");
2604   }
2605
2606   //----------------------------------------------------------------------------
2607   PFieldInfo
2608   TWrapper
2609   ::CrFieldInfo(const PMeshInfo& theMeshInfo,
2610                 TInt theNbComp,
2611                 ETypeChamp theType,
2612                 const std::string& theValue,
2613                 EBooleen theIsLocal,
2614                 TInt theNbRef)
2615   {
2616     return PFieldInfo(new TTFieldInfo
2617                       (theMeshInfo,
2618                        theNbComp,
2619                        theType,
2620                        theValue,
2621                        theIsLocal,
2622                        theNbRef));
2623   }
2624
2625   //----------------------------------------------------------------------------
2626   PFieldInfo
2627   TWrapper
2628   ::CrFieldInfo(const PMeshInfo& theMeshInfo,
2629                 const PFieldInfo& theInfo)
2630   {
2631     return PFieldInfo(new TTFieldInfo
2632                       (theMeshInfo,
2633                        theInfo));
2634   }
2635
2636   //----------------------------------------------------------------------------
2637   PFieldInfo
2638   TWrapper
2639   ::GetPFieldInfo(const PMeshInfo& theMeshInfo,
2640                   TInt theId,
2641                   TErr* theErr)
2642   {
2643     TInt aNbComp = GetNbComp(theId);
2644     PFieldInfo anInfo = CrFieldInfo(theMeshInfo, aNbComp);
2645     GetFieldInfo(theId, *anInfo, theErr);
2646
2647 #ifdef _DEBUG_
2648     INITMSG(MYDEBUG,
2649             "GetPFieldInfo "<<
2650             "- aName = '"<<anInfo->GetName()<<"'"<<
2651             "; aType = "<<anInfo->GetType()<<
2652             "; aNbComp = "<<aNbComp<<
2653             std::endl);
2654 #endif
2655
2656     return anInfo;
2657   }
2658
2659   //----------------------------------------------------------------------------
2660   TInt
2661   TWrapper
2662   ::GetNbGauss(TErr* theErr)
2663   {
2664     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
2665
2666     if (theErr && *theErr < 0)
2667       return -1;
2668
2669     return MEDnLocalization(myFile->Id());
2670   }
2671
2672   //----------------------------------------------------------------------------
2673   TGaussInfo::TInfo
2674   TWrapper
2675   ::GetGaussPreInfo(TInt theId,
2676                     TErr* theErr)
2677   {
2678     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
2679
2680     if (theErr && *theErr < 0)
2681       return TGaussInfo::TInfo(TGaussInfo::TKey(ePOINT1, ""), 0);
2682
2683     med_int aNbGaussPoints = med_int();
2684     TVector<char> aName(GetNOMLength()+1);
2685     med_geometry_type aGeom = MED_NONE;
2686
2687     TErr aRet;
2688     med_int dim;
2689     char geointerpname[MED_NAME_SIZE+1] = "";
2690     char ipointstructmeshname[MED_NAME_SIZE+1] = "";
2691     med_int nsectionmeshcell;
2692     med_geometry_type sectiongeotype;
2693     aRet = MEDlocalizationInfo (myFile->Id(),
2694                                 theId,
2695                                 &aName[0],
2696                                 &aGeom,
2697                                 &dim,
2698                                 &aNbGaussPoints,
2699                                 geointerpname,
2700                                 ipointstructmeshname,
2701                                 &nsectionmeshcell,
2702                                 &sectiongeotype);
2703     if (theErr)
2704       *theErr = aRet;
2705     else if (aRet < 0)
2706       EXCEPTION(std::runtime_error, "GetGaussPreInfo - MEDlocalizationInfo(...)");
2707     return TGaussInfo::TInfo(TGaussInfo::TKey(EGeometrieElement(aGeom), &aName[0]),
2708                              TInt(aNbGaussPoints));
2709   }
2710
2711   //----------------------------------------------------------------------------
2712   void
2713   TWrapper
2714   ::GetGaussInfo(TInt theId,
2715                  TGaussInfo& theInfo,
2716                  TErr* theErr)
2717   {
2718     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
2719
2720     if (theErr && *theErr < 0)
2721       return;
2722
2723     TValueHolder<TNodeCoord, med_float> aRefCoord(theInfo.myRefCoord);
2724     TValueHolder<TNodeCoord, med_float> aGaussCoord(theInfo.myGaussCoord);
2725     TValueHolder<TWeight, med_float> aWeight(theInfo.myWeight);
2726     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
2727     TValueHolder<TString, char> aGaussName(theInfo.myName);
2728
2729     TErr aRet;
2730     aRet = MEDlocalizationRd(myFile->Id(),
2731                              &aGaussName,
2732                              aModeSwitch,
2733                              &aRefCoord,
2734                              &aGaussCoord,
2735                              &aWeight);
2736
2737     if (theErr)
2738       *theErr = aRet;
2739     else if (aRet < 0)
2740       EXCEPTION(std::runtime_error, "GetGaussInfo - MEDlocalizationRd(...)");
2741   }
2742
2743   //----------------------------------------------------------------------------
2744   PGaussInfo
2745   TWrapper
2746   ::CrGaussInfo(const TGaussInfo::TInfo& theInfo,
2747                 EModeSwitch theMode)
2748   {
2749     return PGaussInfo(new TTGaussInfo
2750                       (theInfo,
2751                        theMode));
2752   }
2753
2754   //-----------------------------------------------------------------
2755   TInt
2756   TWrapper
2757   ::GetNbTimeStamps(const MED::TFieldInfo& theInfo,
2758                     const MED::TEntityInfo& theEntityInfo,
2759                     EEntiteMaillage& theEntity,
2760                     TGeom2Size& theGeom2Size,
2761                     TErr* theErr)
2762   {
2763     theEntity = EEntiteMaillage(-1);
2764     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
2765
2766     if (theErr) {
2767       if (theEntityInfo.empty())
2768         *theErr = -1;
2769       if (*theErr < 0)
2770         return -1;
2771     }
2772     else if (theEntityInfo.empty())
2773       EXCEPTION(std::runtime_error, "GetNbTimeStamps - There is no any Entity on the Mesh");
2774
2775     bool anIsPerformAdditionalCheck = GetNbMeshes() > 1;
2776
2777     theGeom2Size.clear();
2778     TInt aNbTimeStamps = 0;
2779     TIdt anId = myFile->Id();
2780
2781     MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
2782     TValueHolder<TString, char> aFieldName(anInfo.myName);
2783     MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo;
2784
2785     // workaround for IPAL13676
2786     MED::TEntityInfo localEntityInfo = theEntityInfo;
2787     TEntityInfo::iterator anLocalIter = localEntityInfo.find(eMAILLE);
2788     if (anLocalIter != localEntityInfo.end()) {
2789       localEntityInfo[eNOEUD_ELEMENT] = anLocalIter->second;
2790     }
2791
2792     TEntityInfo::const_iterator anIter = localEntityInfo.begin();
2793     for (; anIter != localEntityInfo.end(); anIter++) {
2794       med_entity_type anEntity = med_entity_type(anIter->first);
2795       const TGeom2Size& aGeom2Size = anIter->second;
2796       TGeom2Size::const_iterator anGeomIter = aGeom2Size.begin();
2797       for (; anGeomIter != aGeom2Size.end(); anGeomIter++) {
2798         med_geometry_type aGeom = med_geometry_type(anGeomIter->first);
2799         char aMeshName[MED_NAME_SIZE+1];
2800         med_bool islocal;
2801         med_field_type ft;
2802         char dtunit[MED_SNAME_SIZE+1];
2803         med_int myNbComp = MEDfieldnComponentByName(anId, &aFieldName);
2804         char *cname=new char[myNbComp*MED_SNAME_SIZE+1];
2805         char *unitname=new char[myNbComp*MED_SNAME_SIZE+1];
2806         TInt aNbStamps;
2807         MEDfieldInfoByName(anId,
2808                            &aFieldName,
2809                            aMeshName,
2810                            &islocal,
2811                            &ft,
2812                            cname,
2813                            unitname,
2814                            dtunit,
2815                            &aNbStamps);
2816         delete [] cname;
2817         delete [] unitname;
2818         med_int nval = 0;
2819         med_int aNumDt;
2820         med_int aNumOrd;
2821         med_float aDt;
2822         if (aNbStamps > 0)
2823           {
2824             MEDfieldComputingStepInfo(anId,
2825                                       &aFieldName,
2826                                       1,
2827                                       &aNumDt,
2828                                       &aNumOrd,
2829                                       &aDt);
2830             char profilename[MED_NAME_SIZE+1];
2831             char locname[MED_NAME_SIZE+1];
2832             med_int profilsize;
2833             med_int aNbGauss;
2834
2835             // protection from crash (division by zero)
2836             // inside MEDfieldnValueWithProfile function
2837             // caused by the workaround for IPAL13676 (see above)
2838             if (anEntity == MED_NODE_ELEMENT && aGeom % 100 == 0)
2839               continue;
2840
2841             nval = MEDfieldnValueWithProfile(anId,
2842                                              &aFieldName,
2843                                              aNumDt,
2844                                              aNumOrd,
2845                                              anEntity,
2846                                              med_geometry_type(aGeom),
2847                                              1,
2848                                              MED_COMPACT_STMODE,
2849                                              profilename,
2850                                              &profilsize,
2851                                              locname,
2852                                              &aNbGauss);
2853           }
2854         bool anIsSatisfied =(nval > 0);
2855         if (anIsSatisfied) {
2856           INITMSG(MYDEBUG,
2857                   "GetNbTimeStamps aNbTimeStamps = "<<aNbStamps<<
2858                   "; aGeom = "<<aGeom<<"; anEntity = "<<anEntity<<"\n");
2859           if (anIsPerformAdditionalCheck) {
2860             anIsSatisfied = !strcmp(&aMeshName[0], &aMeshInfo.myName[0]);
2861             if (!anIsSatisfied) {
2862               INITMSG(MYDEBUG,
2863                       "GetNbTimeStamps aMeshName = '"<<&aMeshName[0]<<"' != "<<
2864                       "; aMeshInfo.myName = '"<<&aMeshInfo.myName[0]<<"'\n");
2865             }
2866           }
2867         }
2868         if (anIsSatisfied) {
2869           theGeom2Size[EGeometrieElement(aGeom)] = anGeomIter->second;
2870           theEntity = EEntiteMaillage(anEntity);
2871           aNbTimeStamps = aNbStamps;
2872         }
2873       }
2874       if (!theGeom2Size.empty())
2875         break;
2876     }
2877     return aNbTimeStamps;
2878   }
2879
2880   //----------------------------------------------------------------------------
2881   void
2882   TWrapper
2883   ::GetTimeStampInfo(TInt theTimeStampId,
2884                      MED::TTimeStampInfo& theInfo,
2885                      TErr* theErr)
2886   {
2887     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
2888
2889     const TGeom2Size& aGeom2Size = theInfo.myGeom2Size;
2890
2891     if (theErr) {
2892       if (aGeom2Size.empty())
2893         *theErr = -1;
2894       if (*theErr < 0)
2895         return;
2896     }
2897     else if (aGeom2Size.empty())
2898       EXCEPTION(std::runtime_error, "GetTimeStampInfo - There is no any cell");
2899
2900     MED::TFieldInfo& aFieldInfo = *theInfo.myFieldInfo;
2901     MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
2902
2903     TValueHolder<TString, char> aFieldName(aFieldInfo.myName);
2904     TValueHolder<EEntiteMaillage, med_entity_type> anEntity(theInfo.myEntity);
2905     TValueHolder<TInt, med_int> aNumDt(theInfo.myNumDt);
2906     TValueHolder<TInt, med_int> aNumOrd(theInfo.myNumOrd);
2907     TValueHolder<TString, char> anUnitDt(theInfo.myUnitDt);
2908     TValueHolder<TFloat, med_float> aDt(theInfo.myDt);
2909     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
2910     TValueHolder<EBooleen, med_bool> anIsLocal(aFieldInfo.myIsLocal);
2911     TValueHolder<TInt, med_int> aNbRef(aFieldInfo.myNbRef);
2912
2913     TGeom2NbGauss& aGeom2NbGauss = theInfo.myGeom2NbGauss;
2914
2915     // just to get a time stamp unit (anUnitDt)
2916     med_field_type aFieldType;
2917     med_int aNbComp = MEDfieldnComponentByName(myFile->Id(), &aFieldName);
2918     char *aCompName = new char[aNbComp*MED_SNAME_SIZE+1];
2919     char *aCompUnit = new char[aNbComp*MED_SNAME_SIZE+1];
2920     TInt aNbStamps;
2921     MEDfieldInfoByName(myFile->Id(),
2922                        &aFieldName,
2923                        &aMeshName,
2924                        &anIsLocal,
2925                        &aFieldType,
2926                        aCompName,
2927                        aCompUnit,
2928                        &anUnitDt,
2929                        &aNbStamps);
2930     delete [] aCompName;
2931     delete [] aCompUnit;
2932
2933     TGeom2Size::const_iterator anIter = aGeom2Size.begin();
2934     for (; anIter != aGeom2Size.end(); anIter++) {
2935       const EGeometrieElement& aGeom = anIter->first;
2936       med_int aNbGauss = -1;
2937
2938       TErr aRet;
2939       aRet = MEDfieldComputingStepInfo(myFile->Id(),
2940                                        &aFieldName,
2941                                        theTimeStampId,
2942                                        &aNumDt,
2943                                        &aNumOrd,
2944                                        &aDt);
2945       char profilename[MED_NAME_SIZE+1];
2946       med_int profilsize;
2947       char locname[MED_NAME_SIZE+1];
2948       MEDfieldnValueWithProfile(myFile->Id(),
2949                                 &aFieldName,
2950                                 aNumDt,
2951                                 aNumOrd,
2952                                 anEntity,
2953                                 med_geometry_type(aGeom),
2954                                 1,
2955                                 MED_COMPACT_STMODE,
2956                                 profilename,
2957                                 &profilsize,
2958                                 locname,
2959                                 &aNbGauss);
2960
2961       static TInt MAX_NB_GAUSS_POINTS = 32;
2962       if (aNbGauss <= 0 || aNbGauss > MAX_NB_GAUSS_POINTS)
2963         aNbGauss = 1;
2964
2965       aGeom2NbGauss[aGeom] = aNbGauss;
2966
2967       if (theErr)
2968         *theErr = aRet;
2969       else if (aRet < 0)
2970         EXCEPTION(std::runtime_error, "GetTimeStampInfo - MEDfieldnValueWithProfile(...)");
2971     }
2972   }
2973
2974   //----------------------------------------------------------------------------
2975   PTimeStampInfo
2976   TWrapper
2977   ::CrTimeStampInfo(const PFieldInfo& theFieldInfo,
2978                     EEntiteMaillage theEntity,
2979                     const TGeom2Size& theGeom2Size,
2980                     const TGeom2NbGauss& theGeom2NbGauss,
2981                     TInt theNumDt,
2982                     TInt theNumOrd,
2983                     TFloat theDt,
2984                     const std::string& theUnitDt,
2985                     const TGeom2Gauss& theGeom2Gauss)
2986   {
2987     return PTimeStampInfo(new TTTimeStampInfo
2988                           (theFieldInfo,
2989                            theEntity,
2990                            theGeom2Size,
2991                            theGeom2NbGauss,
2992                            theNumDt,
2993                            theNumOrd,
2994                            theDt,
2995                            theUnitDt,
2996                            theGeom2Gauss));
2997   }
2998
2999   //----------------------------------------------------------------------------
3000   PTimeStampInfo
3001   TWrapper
3002   ::CrTimeStampInfo(const PFieldInfo& theFieldInfo,
3003                     const PTimeStampInfo& theInfo)
3004   {
3005     return PTimeStampInfo(new TTTimeStampInfo
3006                           (theFieldInfo,
3007                            theInfo));
3008   }
3009
3010   //----------------------------------------------------------------------------
3011   PTimeStampInfo
3012   TWrapper
3013   ::GetPTimeStampInfo(const PFieldInfo& theFieldInfo,
3014                       EEntiteMaillage theEntity,
3015                       const TGeom2Size& theGeom2Size,
3016                       TInt theId,
3017                       TErr* theErr)
3018   {
3019     PTimeStampInfo anInfo = CrTimeStampInfo(theFieldInfo, theEntity, theGeom2Size);
3020     GetTimeStampInfo(theId, *anInfo, theErr);
3021
3022 #ifdef _DEBUG_
3023     INITMSG(MYDEBUG, "GetPTimeStampInfo - anEntity = "<<anInfo->GetEntity()<<"\n");
3024     TGeom2NbGauss& aGeom2NbGauss = anInfo->myGeom2NbGauss;
3025     TGeom2NbGauss::const_iterator anIter = aGeom2NbGauss.begin();
3026     for (; anIter != aGeom2NbGauss.end(); anIter++) {
3027       const EGeometrieElement& aGeom = anIter->first;
3028       INITMSG(MYDEBUG, "aGeom = "<<aGeom<<" - "<<aGeom2NbGauss[aGeom]<<";\n");
3029     }
3030 #endif
3031
3032     return anInfo;
3033   }
3034
3035   //----------------------------------------------------------------------------
3036   TInt
3037   TWrapper
3038   ::GetNbProfiles(TErr* theErr)
3039   {
3040     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
3041
3042     if (theErr && *theErr < 0)
3043       return -1;
3044
3045     return MEDnProfile(myFile->Id());
3046   }
3047
3048   //----------------------------------------------------------------------------
3049   TProfileInfo::TInfo
3050   TWrapper
3051   ::GetProfilePreInfo(TInt theId,
3052                       TErr* theErr)
3053   {
3054     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
3055
3056     if (theErr && *theErr < 0)
3057       return TProfileInfo::TInfo();
3058
3059     med_int aSize = -1;
3060     TVector<char> aName(GetNOMLength()+1);
3061
3062     TErr aRet;
3063     aRet = MEDprofileInfo(myFile->Id(),
3064                           theId,
3065                           &aName[0],
3066                           &aSize);
3067     if (theErr)
3068       *theErr = aRet;
3069     else if (aRet < 0)
3070       EXCEPTION(std::runtime_error, "GetProfilePreInfo - MEDprofileInfo(...)");
3071
3072     return TProfileInfo::TInfo(&aName[0], aSize);
3073   }
3074
3075   //----------------------------------------------------------------------------
3076   void
3077   TWrapper
3078   ::GetProfileInfo(TInt theId,
3079                    TProfileInfo& theInfo,
3080                    TErr* theErr)
3081   {
3082     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
3083
3084     if (theErr && *theErr < 0)
3085       return;
3086
3087     TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo);
3088     TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
3089     TValueHolder<TString, char> aProfileName(anInfo.myName);
3090
3091     TErr aRet;
3092     aRet = MEDprofileRd(myFile->Id(),
3093                         &aProfileName,
3094                         &anElemNum);
3095     if (theErr)
3096       *theErr = aRet;
3097     else if (aRet < 0)
3098       EXCEPTION(std::runtime_error, "GetProfileInfo - MEDprofileRd(...)");
3099   }
3100
3101   //----------------------------------------------------------------------------
3102   void
3103   TWrapper
3104   ::SetProfileInfo(const TProfileInfo& theInfo,
3105                    TErr* theErr)
3106   {
3107     TErr aRet;
3108     SetProfileInfo(theInfo, eLECTURE_ECRITURE, &aRet);
3109
3110     if (aRet < 0)
3111       SetProfileInfo(theInfo, eLECTURE_AJOUT, &aRet);
3112
3113     if (aRet < 0)
3114       SetProfileInfo(theInfo, eCREATION, &aRet);
3115
3116     if (theErr)
3117       *theErr = aRet;
3118   }
3119
3120   //----------------------------------------------------------------------------
3121   void
3122   TWrapper
3123   ::SetProfileInfo(const TProfileInfo& theInfo,
3124                    EModeAcces theMode,
3125                    TErr* theErr)
3126   {
3127     TFileWrapper aFileWrapper(myFile, theMode, theErr);
3128
3129     if (theErr && *theErr < 0)
3130       return;
3131
3132     TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo);
3133     TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
3134     TValueHolder<TString, char>     aProfileName(anInfo.myName);
3135
3136     TErr aRet;
3137     aRet = MEDprofileWr(myFile->Id(),      // descripteur du fichier.
3138                         &aProfileName,     // tableau de valeurs du profil.
3139                         theInfo.GetSize(), // taille du profil.
3140                         &anElemNum);       // nom profil.
3141     if (theErr)
3142       *theErr = aRet;
3143     else if (aRet < 0)
3144       EXCEPTION(std::runtime_error, "SetProfileInfo - MEDprofileWr(...)");
3145   }
3146
3147   //----------------------------------------------------------------------------
3148   PProfileInfo
3149   TWrapper
3150   ::CrProfileInfo(const TProfileInfo::TInfo& theInfo,
3151                   EModeProfil theMode)
3152   {
3153     return PProfileInfo(new TTProfileInfo
3154                         (theInfo,
3155                          theMode));
3156   }
3157
3158   //----------------------------------------------------------------------------
3159   PProfileInfo
3160   TWrapper
3161   ::GetPProfileInfo(TInt theId,
3162                     EModeProfil theMode,
3163                     TErr* theErr)
3164   {
3165     TProfileInfo::TInfo aPreInfo = GetProfilePreInfo(theId);
3166     PProfileInfo anInfo = CrProfileInfo(aPreInfo, theMode);
3167     GetProfileInfo(theId, *anInfo, theErr);
3168
3169     return anInfo;
3170   }
3171
3172   //----------------------------------------------------------------------------
3173   void
3174   TWrapper
3175   ::GetTimeStampValue(const PTimeStampValueBase& theTimeStampValue,
3176                       const TMKey2Profile& theMKey2Profile,
3177                       const TKey2Gauss& theKey2Gauss,
3178                       TErr* theErr)
3179   {
3180     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
3181
3182     if (theErr && *theErr < 0)
3183       return;
3184
3185     TIdt anId = myFile->Id();
3186
3187     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theTimeStampValue->myModeSwitch);
3188     MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile;
3189
3190     MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo;
3191     TValueHolder<EEntiteMaillage, med_entity_type> anEntity(aTimeStampInfo->myEntity);
3192     TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt);
3193     TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd);
3194
3195     MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo;
3196     TValueHolder<TString, char> aFieldName(aFieldInfo->myName);
3197     TValueHolder<EBooleen, med_bool> anIsLocal(aFieldInfo->myIsLocal);
3198
3199     MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo;
3200     TValueHolder<TString, char> aMeshName(aMeshInfo->myName);
3201
3202     TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->myGeom2Gauss;
3203     TVector<char> aGaussName(GetNOMLength()+1);
3204
3205     med_storage_mode aProfileMode = med_storage_mode(boost::get<0>(theMKey2Profile));
3206     MED::TKey2Profile aKey2Profile = boost::get<1>(theMKey2Profile);
3207     TVector<char> aProfileName(GetNOMLength()+1);
3208
3209     TGeom2Size& aGeom2Size = aTimeStampInfo->myGeom2Size;
3210     TGeom2Size::iterator anIter = aGeom2Size.begin();
3211     for (; anIter != aGeom2Size.end(); anIter++) {
3212       EGeometrieElement aGeom = anIter->first;
3213       TInt aNbElem = anIter->second;
3214       med_int profilesize, aNbGauss;
3215
3216       TInt aNbVal = MEDfieldnValueWithProfile(anId,
3217                                               &aFieldName,
3218                                               aNumDt,
3219                                               aNumOrd,
3220                                               anEntity,
3221                                               med_geometry_type(aGeom),
3222                                               1,
3223                                               aProfileMode,
3224                                               &aProfileName[0],
3225                                               &profilesize,
3226                                               &aGaussName[0],
3227                                               &aNbGauss);
3228
3229       if (aNbVal <= 0) {
3230         if (theErr) {
3231           *theErr = -1;
3232           return;
3233         }
3234         EXCEPTION(std::runtime_error, "GetTimeStampValue - MEDfieldnValueWithProfile(...) - aNbVal == "<<aNbVal<<" <= 0");
3235       }
3236
3237       TInt aNbComp = aFieldInfo->myNbComp;
3238       TInt aNbValue = aNbVal;// / aNbGauss; rules in MED changed
3239       theTimeStampValue->AllocateValue(aGeom,
3240                                        aNbValue,
3241                                        aNbGauss,
3242                                        aNbComp);
3243       TInt aValueSize = theTimeStampValue->GetValueSize(aGeom);
3244
3245       INITMSG(MYDEBUG,
3246               "TWrapper::GetTimeStampValue - aGeom = "<<aGeom<<
3247               "; aNbVal = "<<aNbVal<<
3248               "; aNbValue = "<<aNbValue<<
3249               "; aNbGauss = "<<aNbGauss<<
3250               "; aNbComp = "<<aNbComp<<
3251               std::endl);
3252
3253       TErr aRet = MEDfieldValueWithProfileRd(anId,
3254                                              &aFieldName,
3255                                              aNumDt,
3256                                              aNumOrd,
3257                                              anEntity,
3258                                              med_geometry_type(aGeom),
3259                                              aProfileMode,
3260                                              &aProfileName[0],
3261                                              aModeSwitch,
3262                                              MED_ALL_CONSTITUENT,
3263                                              theTimeStampValue->GetValuePtr(aGeom));
3264       if (aRet < 0) {
3265         if (theErr) {
3266           *theErr = MED_FALSE;
3267           return;
3268         }
3269         EXCEPTION(std::runtime_error, "GetTimeStampValue - MEDfieldValueWithProfileRd(...)");
3270       }
3271
3272       MED::PGaussInfo aGaussInfo;
3273       TGaussInfo::TKey aKey(aGeom, &aGaussName[0]);
3274       if (strcmp(&aGaussName[0], "") != 0) {
3275         MED::TKey2Gauss::const_iterator anIter = theKey2Gauss.find(aKey);
3276         if (anIter != theKey2Gauss.end()) {
3277           aGaussInfo = anIter->second;
3278           aGeom2Gauss[aGeom] = aGaussInfo;
3279         }
3280       }
3281
3282       MED::PProfileInfo aProfileInfo;
3283       if (strcmp(&aProfileName[0], MED_NO_PROFILE) != 0) {
3284         MED::TKey2Profile::const_iterator anIter = aKey2Profile.find(&aProfileName[0]);
3285         if (anIter != aKey2Profile.end()) {
3286           aProfileInfo = anIter->second;
3287           aGeom2Profile[aGeom] = aProfileInfo;
3288         }
3289       }
3290
3291       if (aGaussInfo && aNbGauss != aGaussInfo->GetNbGauss()) {
3292         if (theErr) {
3293           *theErr = MED_FALSE;
3294           return;
3295         }
3296         EXCEPTION(std::runtime_error, "GetTimeStampValue - aNbGauss != aGaussInfo->GetNbGauss()");
3297       }
3298
3299       if (aProfileInfo && aProfileInfo->IsPresent()) {
3300         TInt aNbSubElem = aProfileInfo->GetSize();
3301         TInt aProfileSize = aNbSubElem*aNbComp*aNbGauss;
3302         if (aProfileSize != aValueSize) {
3303           if (theErr) {
3304             *theErr = -1;
3305             return;
3306           }
3307           EXCEPTION(std::runtime_error,
3308                     "GetTimeStampValue - aProfileSize("<<aProfileSize<<
3309                     ") != aValueSize("<<aValueSize<<
3310                     "); aNbVal = "<<aNbVal<<
3311                     "; anEntity = "<<anEntity<<
3312                     "; aGeom = "<<aGeom<<
3313                     "; aNbElem = "<<aNbElem<<
3314                     "; aNbSubElem = "<<aNbSubElem<<
3315                     "; aNbComp = "<<aNbComp<<
3316                     "; aNbGauss = "<<aNbGauss<<
3317                     "");
3318         }
3319       }
3320       else{
3321         if ((aProfileMode == MED_GLOBAL_STMODE) && (aNbElem != aNbValue)) {
3322           if (theErr) {
3323             *theErr = -1;
3324             return;
3325           }
3326           EXCEPTION(std::runtime_error,
3327                     "GetTimeStampValue - aNbElem("<<aNbElem<<
3328                     ") != aNbValue("<<aNbValue<<
3329                     "); aNbVal = "<<aNbVal<<
3330                     "; anEntity = "<<anEntity<<
3331                     "; aGeom = "<<aGeom<<
3332                     "; aNbElem = "<<aNbElem<<
3333                     "; aNbComp = "<<aNbComp<<
3334                     "; aNbGauss = "<<aNbGauss<<
3335                     "");
3336         }
3337       }
3338     }
3339   }
3340
3341   //----------------------------------------------------------------------------
3342   void
3343   TWrapper
3344   ::SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue,
3345                       TErr* theErr)
3346   {
3347     TErr aRet;
3348     SetTimeStampValue(theTimeStampValue, eLECTURE_ECRITURE, &aRet);
3349
3350     if (aRet < 0)
3351       SetTimeStampValue(theTimeStampValue, eLECTURE_AJOUT, &aRet);
3352
3353     if (theErr)
3354       *theErr = aRet;
3355   }
3356
3357   //----------------------------------------------------------------------------
3358   void
3359   TWrapper
3360   ::SetTimeStampValue(const MED::PTimeStampValueBase& theTimeStampValue,
3361                       EModeAcces theMode,
3362                       TErr* theErr)
3363   {
3364     TFileWrapper aFileWrapper(myFile, theMode, theErr);
3365
3366     if (theErr && *theErr < 0)
3367       return;
3368
3369     TErr aRet;
3370     TIdt anId = myFile->Id();
3371
3372     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theTimeStampValue->myModeSwitch);
3373     MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile;
3374
3375     MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo;
3376     TValueHolder<EEntiteMaillage, med_entity_type> anEntity(aTimeStampInfo->myEntity);
3377     TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt);
3378     TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd);
3379     TValueHolder<TString, char> anUnitDt(aTimeStampInfo->myUnitDt);
3380     TValueHolder<TFloat, med_float> aDt(aTimeStampInfo->myDt);
3381     MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->myGeom2Gauss;
3382
3383     MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo;
3384     TValueHolder<TString, char> aFieldName(aFieldInfo->myName);
3385
3386     MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo;
3387     TValueHolder<TString, char> aMeshName(aMeshInfo->myName);
3388
3389     const TGeomSet& aGeomSet = theTimeStampValue->myGeomSet;
3390     TGeomSet::const_iterator anIter = aGeomSet.begin();
3391     for (; anIter != aGeomSet.end(); anIter++) {
3392       EGeometrieElement aGeom = *anIter;
3393
3394       TVector<char> aGaussName(GetNOMLength()+1);
3395       MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aGeom);
3396       if (aGaussIter != aGeom2Gauss.end()) {
3397         MED::PGaussInfo aGaussInfo = aGaussIter->second;
3398         strcpy(&aGaussName[0], &aGaussInfo->myName[0]);
3399       }
3400
3401       TVector<char> aProfileName(GetNOMLength()+1);
3402       med_storage_mode aProfileMode = med_storage_mode(eNO_PFLMOD);
3403       MED::TGeom2Profile::const_iterator aProfileIter = aGeom2Profile.find(aGeom);
3404       if (aProfileIter != aGeom2Profile.end()) {
3405         MED::PProfileInfo aProfileInfo = aProfileIter->second;
3406         aProfileMode = med_storage_mode(aProfileInfo->myMode);
3407         strcpy(&aProfileName[0], &aProfileInfo->myName[0]);
3408       }
3409
3410       med_int aNbVal = theTimeStampValue->GetNbVal(aGeom);
3411
3412       aRet = MEDfieldValueWithProfileWr(anId,
3413                                         &aFieldName,
3414                                         aNumDt,
3415                                         aNumOrd,
3416                                         aDt,
3417                                         anEntity,
3418                                         med_geometry_type(aGeom),
3419                                         aProfileMode,
3420                                         &aProfileName[0],
3421                                         &aGaussName[0],
3422                                         aModeSwitch,
3423                                         MED_ALL_CONSTITUENT,
3424                                         aNbVal,
3425                                         theTimeStampValue->GetValuePtr(aGeom));
3426       if (aRet < 0) {
3427         if (theErr) {
3428           *theErr = MED_FALSE;
3429           break;
3430         }
3431         EXCEPTION(std::runtime_error, "SetTimeStampValue - MEDfieldValueWithProfileWr(...)");
3432       }
3433
3434     }
3435
3436     INITMSG(MYDEBUG, "TWrapper::SetTimeStampValue - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
3437   }
3438
3439   //----------------------------------------------------------------------------
3440   PTimeStampValueBase
3441   TWrapper
3442   ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3443                      ETypeChamp theTypeChamp,
3444                      const TGeom2Profile& theGeom2Profile,
3445                      EModeSwitch theMode)
3446   {
3447     if (theTypeChamp == eFLOAT64)
3448       return PTimeStampValueBase(new TTTimeStampValue<TFloatMeshValue>
3449                                  (theTimeStampInfo,
3450                                   theTypeChamp,
3451                                   theGeom2Profile,
3452                                   theMode));
3453     return PTimeStampValueBase(new TTTimeStampValue<TIntMeshValue>
3454                                (theTimeStampInfo,
3455                                 theTypeChamp,
3456                                 theGeom2Profile,
3457                                 theMode));
3458   }
3459
3460   //----------------------------------------------------------------------------
3461   PTimeStampValueBase
3462   TWrapper
3463   ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3464                      const TGeom2Profile& theGeom2Profile,
3465                      EModeSwitch theMode)
3466   {
3467     PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
3468     return CrTimeStampValue(theTimeStampInfo,
3469                             aFieldInfo->GetType(),
3470                             theGeom2Profile,
3471                             theMode);
3472   }
3473
3474   //----------------------------------------------------------------------------
3475   PTimeStampValueBase
3476   TWrapper
3477   ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3478                      const PTimeStampValueBase& theInfo,
3479                      ETypeChamp theTypeChamp)
3480   {
3481     if (theTypeChamp == eFLOAT64)
3482       return PTimeStampValueBase(new TTTimeStampValue<TFloatMeshValue>
3483                                  (theTimeStampInfo,
3484                                   theInfo,
3485                                   theTypeChamp));
3486     return PTimeStampValueBase(new TTTimeStampValue<TIntMeshValue>
3487                                (theTimeStampInfo,
3488                                 theInfo,
3489                                 theTypeChamp));
3490   }
3491
3492   //----------------------------------------------------------------------------
3493   PTimeStampValueBase
3494   TWrapper
3495   ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3496                      const PTimeStampValueBase& theInfo)
3497   {
3498     PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
3499     return CrTimeStampValue(theTimeStampInfo,
3500                             theInfo,
3501                             aFieldInfo->GetType());
3502   }
3503
3504   //----------------------------------------------------------------------------
3505   PTimeStampValueBase
3506   TWrapper
3507   ::GetPTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3508                        const TMKey2Profile& theMKey2Profile,
3509                        const TKey2Gauss& theKey2Gauss,
3510                        TErr* theErr)
3511   {
3512     PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
3513     PTimeStampValueBase anInfo = CrTimeStampValue(theTimeStampInfo,
3514                                                   aFieldInfo->GetType());
3515     GetTimeStampValue(anInfo,
3516                       theMKey2Profile,
3517                       theKey2Gauss,
3518                       theErr);
3519 #ifdef _DEBUG_
3520     if (aFieldInfo->GetType() == eFLOAT64)
3521       Print<TFloatTimeStampValue>(anInfo);
3522     else
3523       Print<TIntTimeStampValue>(anInfo);
3524 #endif
3525     return anInfo;
3526   }
3527
3528   //----------------------------------------------------------------------------
3529   void
3530   TWrapper
3531   ::GetTimeStampVal(const PTimeStampVal& theVal,
3532                     const TMKey2Profile& theMKey2Profile,
3533                     const TKey2Gauss& theKey2Gauss,
3534                     TErr* theErr)
3535   {
3536     PTimeStampInfo aTimeStampInfo = theVal->GetTimeStampInfo();
3537     PFieldInfo aFieldInfo = aTimeStampInfo->GetFieldInfo();
3538     if (aFieldInfo->GetType() == eFLOAT64)
3539       GetTimeStampValue(theVal,
3540                         theMKey2Profile,
3541                         theKey2Gauss,
3542                         theErr);
3543     else{
3544       PTimeStampValueBase aVal = CrTimeStampValue(aTimeStampInfo,
3545                                                   theVal,
3546                                                   eINT);
3547       GetTimeStampValue(aVal,
3548                         theMKey2Profile,
3549                         theKey2Gauss,
3550                         theErr);
3551       CopyTimeStampValueBase(aVal, theVal);
3552     }
3553   }
3554
3555   //----------------------------------------------------------------------------
3556   void
3557   TWrapper
3558   ::SetTimeStamp(const PTimeStampVal& theVal,
3559                  TErr* theErr)
3560   {
3561     PTimeStampInfo aTimeStampInfo = theVal->GetTimeStampInfo();
3562     PFieldInfo aFieldInfo = aTimeStampInfo->GetFieldInfo();
3563     if (aFieldInfo->GetType() == eFLOAT64)
3564       SetTimeStampValue(theVal, theErr);
3565     else{
3566       PTimeStampValueBase aVal = CrTimeStampValue(aTimeStampInfo,
3567                                                   eINT,
3568                                                   theVal->GetGeom2Profile(),
3569                                                   theVal->GetModeSwitch());
3570       CopyTimeStampValueBase(theVal, aVal);
3571       SetTimeStampValue(aVal, theErr);
3572     }
3573   }
3574
3575   //----------------------------------------------------------------------------
3576   PTimeStampVal
3577   TWrapper
3578   ::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
3579                    const TGeom2Profile& theGeom2Profile,
3580                    EModeSwitch theMode)
3581   {
3582     return CrTimeStampValue(theTimeStampInfo,
3583                             eFLOAT64,
3584                             theGeom2Profile,
3585                             theMode);
3586   }
3587
3588   //----------------------------------------------------------------------------
3589   PTimeStampVal
3590   TWrapper
3591   ::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
3592                    const PTimeStampVal& theInfo)
3593   {
3594     return CrTimeStampValue(theTimeStampInfo,
3595                             theInfo,
3596                             eFLOAT64);
3597   }
3598
3599   //----------------------------------------------------------------------------
3600   PTimeStampVal
3601   TWrapper
3602   ::GetPTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
3603                      const TMKey2Profile& theMKey2Profile,
3604                      const TKey2Gauss& theKey2Gauss,
3605                      TErr* theErr)
3606   {
3607     PTimeStampVal anInfo = CrTimeStampVal(theTimeStampInfo);
3608     GetTimeStampVal(anInfo,
3609                     theMKey2Profile,
3610                     theKey2Gauss,
3611                     theErr);
3612     return anInfo;
3613   }
3614
3615   //----------------------------------------------------------------------------
3616   PGrilleInfo
3617   TWrapper
3618   ::GetPGrilleInfo(const PMeshInfo& theMeshInfo)
3619   {
3620     if (theMeshInfo->GetType() != eSTRUCTURE)
3621       return PGrilleInfo();
3622
3623     EGrilleType type;
3624     GetGrilleType(*theMeshInfo, type);
3625     PGrilleInfo anInfo;
3626     if (type == eGRILLE_STANDARD) {
3627       const TInt nnoeuds = GetNbNodes(*theMeshInfo);
3628       anInfo = CrGrilleInfo(theMeshInfo, type, nnoeuds);
3629     }
3630     else {
3631       TIntVector aVec;
3632       aVec.resize(theMeshInfo->GetDim());
3633       for (int aAxe=0;aAxe<theMeshInfo->GetDim();aAxe++) {
3634         ETable aATable = eCOOR_IND1;
3635         switch (aAxe) {
3636         case 0:
3637           aATable = eCOOR_IND1;
3638           break;
3639         case 1:
3640           aATable = eCOOR_IND2;
3641           break;
3642         case 2:
3643           aATable = eCOOR_IND3;
3644           break;
3645         }
3646         aVec[aAxe] = GetNbNodes(*theMeshInfo, aATable);
3647       }
3648       anInfo = CrGrilleInfo(theMeshInfo, type, aVec);
3649     }
3650
3651     GetGrilleInfo(anInfo);
3652     anInfo->SetGrilleType(type);
3653
3654 #ifdef _DEBUG_
3655     INITMSG(MYDEBUG, "GetPGrilleInfo: ");
3656     {
3657       TInt aNbElem = anInfo->GetNbNodes();
3658       BEGMSG(MYVALUEDEBUG, "GetFamNumNode: ");
3659       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
3660         ADDMSG(MYVALUEDEBUG, anInfo->GetFamNumNode(iElem)<<", ");
3661       }
3662       TInt aNbCells = anInfo->GetNbCells();
3663       BEGMSG(MYVALUEDEBUG, "GetFamNum: ");
3664       for (TInt iElem = 0; iElem < aNbCells; iElem++) {
3665         ADDMSG(MYVALUEDEBUG, anInfo->GetFamNum(iElem)<<", ");
3666       }
3667       ADDMSG(MYVALUEDEBUG, std::endl);
3668       BEGMSG(MYVALUEDEBUG, "GetCoordName: ");
3669       for (TInt iElem = 0; iElem < theMeshInfo->GetDim(); iElem++) {
3670         ADDMSG(MYVALUEDEBUG, anInfo->GetCoordName(iElem)<<", ");
3671       }
3672       ADDMSG(MYVALUEDEBUG, std::endl);
3673       BEGMSG(MYVALUEDEBUG, "GetCoordUnit: ");
3674       for (TInt iElem = 0; iElem < theMeshInfo->GetDim(); iElem++) {
3675         ADDMSG(MYVALUEDEBUG, anInfo->GetCoordUnit(iElem)<<", ");
3676       }
3677       ADDMSG(MYVALUEDEBUG, std::endl);
3678
3679     }
3680 #endif
3681
3682     return anInfo;
3683   }
3684
3685   //----------------------------------------------------------------------------
3686   PGrilleInfo
3687   TWrapper
3688   ::GetPGrilleInfo(const PMeshInfo& theMeshInfo,
3689                    const PGrilleInfo& theInfo)
3690   {
3691     PGrilleInfo anInfo = CrGrilleInfo(theMeshInfo, theInfo);
3692     return anInfo;
3693   }
3694
3695   //----------------------------------------------------------------------------
3696   void
3697   TWrapper
3698   ::GetGrilleInfo(TGrilleInfo& theInfo,
3699                   TErr* theErr)
3700   {
3701     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
3702
3703     if (theErr && *theErr < 0)
3704       return;
3705
3706     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
3707     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
3708     EMaillage aMaillageType = aMeshInfo.myType;
3709
3710     GetGrilleType(aMeshInfo, theInfo.myGrilleType, theErr);
3711     EGrilleType aGrilleType = theInfo.myGrilleType;
3712
3713     TErr aRet = 0;
3714     if (aMaillageType == eSTRUCTURE && aGrilleType == eGRILLE_STANDARD) {
3715       GetGrilleStruct(aMeshInfo, theInfo.myGrilleStructure, theErr);
3716
3717       TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord);
3718       TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
3719       TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames);
3720       TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits);
3721       //med_axis_type aRepere;
3722
3723       aRet = MEDmeshNodeCoordinateRd(myFile->Id(),
3724                                      &aMeshName,
3725                                      MED_NO_DT,
3726                                      MED_NO_IT,
3727                                      aModeSwitch,
3728                                      &aCoord);
3729
3730       if (theErr)
3731         *theErr = aRet;
3732       else if (aRet < 0)
3733         EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDmeshNodeCoordinateRd(...)");
3734
3735       //TInt aNbNodes = theInfo.GetNbNodes();//GetNbFamilies(aMeshInfo);
3736       TValueHolder<TElemNum, med_int> aFamNumNode(theInfo.myFamNumNode);
3737
3738       aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
3739                                          &aMeshName,
3740                                          MED_NO_DT,
3741                                          MED_NO_IT,
3742                                          MED_NODE,
3743                                          MED_NO_GEOTYPE,
3744                                          &aFamNumNode);
3745
3746       if (aRet < 0) {
3747         //            if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
3748         {
3749           int mySize = (int)theInfo.myFamNumNode.size();
3750           theInfo.myFamNumNode.clear();
3751           theInfo.myFamNumNode.resize(mySize,0);
3752           aRet = 0;
3753         }
3754         //            else
3755         //              EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...)");
3756       }
3757       if (theErr)
3758         *theErr = aRet;
3759
3760       //============================
3761     }
3762
3763     if (aMaillageType == eSTRUCTURE && aGrilleType != eGRILLE_STANDARD) {
3764       ETable aTable = eCOOR_IND1;
3765       for (med_int anAxis = 1; anAxis <= aMeshInfo.myDim; anAxis++) {
3766         switch (anAxis) {
3767         case 1:
3768           aTable = eCOOR_IND1;
3769           break;
3770         case 2:
3771           aTable = eCOOR_IND2;
3772           break;
3773         case 3:
3774           aTable = eCOOR_IND3;
3775           break;
3776         default:
3777           aRet = -1;
3778         }
3779
3780         if (theErr)
3781           *theErr = aRet;
3782         else if (aRet < 0)
3783           EXCEPTION(std::runtime_error, "GetGrilleInfo - anAxis number out of range(...)");
3784
3785         TInt aNbIndexes = GetNbNodes(aMeshInfo, aTable);
3786         if (aNbIndexes < 0)
3787           EXCEPTION(std::runtime_error, "GetGrilleInfo - Erreur a la lecture de la taille de l'indice");
3788
3789         TValueHolder<TFloatVector, med_float> anIndexes(theInfo.GetIndexes(anAxis-1));
3790         //TValueHolder<ETable, med_data_type > table(aTable);
3791         //char aCompNames[MED_SNAME_SIZE+1];
3792         //char anUnitNames[MED_SNAME_SIZE+1];
3793         aRet=MEDmeshGridIndexCoordinateRd(myFile->Id(),
3794                                           &aMeshName,
3795                                           MED_NO_DT,MED_NO_IT,
3796                                           anAxis,
3797                                           &anIndexes);
3798
3799         //theInfo.SetCoordName(anAxis-1, aCompNames);
3800         //theInfo.SetCoordUnit(anAxis-1, anUnitNames);
3801         theInfo.SetGrilleStructure(anAxis-1, aNbIndexes);
3802
3803         if (theErr)
3804           *theErr = aRet;
3805         else if (aRet < 0)
3806           EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDindicesCoordLire(...)");
3807       }
3808     }
3809
3810     EGeometrieElement aGeom = theInfo.GetGeom();
3811     EEntiteMaillage aEntity = theInfo.GetEntity();
3812     TInt aNbCells = theInfo.GetNbCells();
3813
3814     theInfo.myFamNum.resize(aNbCells);
3815     TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
3816
3817     aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
3818                                        &aMeshName, MED_NO_DT, MED_NO_IT, med_entity_type(aEntity),
3819                                        med_geometry_type(aGeom), &aFamNum);
3820
3821     if (aMeshInfo.myDim == 3)
3822       {
3823         aGeom = theInfo.GetSubGeom();
3824         aEntity = theInfo.GetSubEntity();
3825         aNbCells = theInfo.GetNbSubCells();
3826
3827         theInfo.myFamSubNum.resize(aNbCells, 0);
3828         TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamSubNum);
3829
3830         aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
3831                                            &aMeshName,
3832                                            MED_NO_DT,
3833                                            MED_NO_IT,
3834                                            med_entity_type(aEntity),
3835                                            med_geometry_type(aGeom),
3836                                            &aFamNum);
3837       }
3838     if (aRet < 0) {
3839       //          if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
3840       {
3841         int mySize = (int)theInfo.myFamNumNode.size();
3842         theInfo.myFamNumNode.clear();
3843         theInfo.myFamNumNode.resize(mySize, 0);
3844         aRet = 0;
3845       }
3846       //          else
3847       //            EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...)");
3848     }
3849     if (theErr)
3850       *theErr = aRet;
3851   }
3852
3853   //----------------------------------------------------------------------------
3854   void
3855   TWrapper
3856   ::SetGrilleInfo(const MED::TGrilleInfo& theInfo,
3857                   TErr* theErr)
3858   {
3859     SetGrilleInfo(theInfo, eLECTURE_ECRITURE, theErr);
3860   }
3861
3862   //----------------------------------------------------------------------------
3863   void
3864   TWrapper
3865   ::SetGrilleInfo(const MED::TGrilleInfo& theInfo,
3866                   EModeAcces theMode,
3867                   TErr* theErr)
3868   {
3869     if (theInfo.myMeshInfo->myType != eSTRUCTURE)
3870       return;
3871     TFileWrapper aFileWrapper(myFile, theMode, theErr);
3872
3873     if (theErr && *theErr < 0)
3874       return;
3875
3876     MED::TGrilleInfo& anInfo = const_cast<MED::TGrilleInfo&>(theInfo);
3877
3878     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
3879     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
3880
3881     TValueHolder<EGrilleType, med_grid_type > aGrilleType(anInfo.myGrilleType);
3882
3883     TErr aRet = 0;
3884     aRet = MEDmeshGridTypeRd(myFile->Id(),
3885                              &aMeshName,
3886                              &aGrilleType);
3887     if (theErr)
3888       *theErr = aRet;
3889     else if (aRet < 0)
3890       EXCEPTION(std::runtime_error, "SetGrilleInfo - MEDmeshGridTypeRd(...)");
3891
3892     if (anInfo.myGrilleType == eGRILLE_STANDARD) {
3893       TValueHolder<TNodeCoord, med_float> aCoord(anInfo.myCoord);
3894       TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(anInfo.myModeSwitch);
3895       TValueHolder<TString, char> aCoordNames(anInfo.myCoordNames);
3896       TValueHolder<TString, char> aCoordUnits(anInfo.myCoordUnits);
3897       med_int aNbNoeuds = med_int(anInfo.myCoord.size() / aMeshInfo.myDim);
3898       //med_axis_type aRepere = MED_CARTESIAN;
3899
3900       aRet = MEDmeshNodeCoordinateWr(myFile->Id(),
3901                                      &aMeshName,
3902                                      MED_NO_DT,
3903                                      MED_NO_IT,
3904                                      MED_UNDEF_DT,
3905                                      aModeSwitch,
3906                                      aNbNoeuds,
3907                                      &aCoord);
3908
3909       if (aRet < 0)
3910         EXCEPTION(std::runtime_error, "SetGrilleInfo - MEDmeshNodeCoordinateWr(...)");
3911
3912       TValueHolder<TIntVector, med_int> aGrilleStructure(anInfo.myGrilleStructure);
3913       aRet = MEDmeshGridStructWr(myFile->Id(),
3914                                  &aMeshName,
3915                                  MED_NO_DT,
3916                                  MED_NO_IT,
3917                                  MED_UNDEF_DT,
3918                                  &aGrilleStructure);
3919       if (aRet < 0)
3920         EXCEPTION(std::runtime_error, "SetGrilleInfo - MEDmeshGridStructWr(...)");
3921
3922     }
3923     else {
3924       for (med_int aAxis = 0; aAxis < aMeshInfo.myDim; aAxis++) {
3925         aRet = MEDmeshGridIndexCoordinateWr(myFile->Id(),
3926                                             &aMeshName,
3927                                             MED_NO_DT,
3928                                             MED_NO_IT,
3929                                             MED_UNDEF_DT,
3930                                             aAxis+1,
3931                                             anInfo.GetIndexes(aAxis).size(),
3932                                             &anInfo.GetIndexes(aAxis)[0]);
3933
3934         if (aRet < 0)
3935           EXCEPTION(std::runtime_error, "SetGrilleInfo - MEDmeshGridIndexCoordinateWr(...)");
3936       }
3937
3938     }
3939
3940     return;
3941   }
3942
3943   //----------------------------------------------------------------------------
3944   PGrilleInfo
3945   TWrapper
3946   ::CrGrilleInfo(const PMeshInfo& theMeshInfo,
3947                  const PGrilleInfo& theInfo)
3948   {
3949     return PGrilleInfo(new TTGrilleInfo
3950                        (theMeshInfo,
3951                         theInfo));
3952   }
3953
3954   //----------------------------------------------------------------------------
3955   PGrilleInfo
3956   TWrapper
3957   ::CrGrilleInfo(const PMeshInfo& theMeshInfo)
3958   {
3959     return PGrilleInfo(); // not implemented????
3960   }
3961
3962   //----------------------------------------------------------------------------
3963   PGrilleInfo
3964   TWrapper
3965   ::CrGrilleInfo(const PMeshInfo& theMeshInfo,
3966                  const EGrilleType& type)
3967   {
3968     return PGrilleInfo(new TTGrilleInfo
3969                        (theMeshInfo,
3970                         type));
3971   }
3972
3973   //----------------------------------------------------------------------------
3974   PGrilleInfo
3975   TWrapper
3976   ::CrGrilleInfo(const PMeshInfo& theMeshInfo,
3977                  const EGrilleType& type,
3978                  const TInt& nbNodes)
3979   {
3980     return PGrilleInfo(new TTGrilleInfo
3981                        (theMeshInfo,
3982                         type,
3983                         nbNodes));
3984   }
3985
3986   //----------------------------------------------------------------------------
3987   PGrilleInfo
3988   TWrapper
3989   ::CrGrilleInfo(const PMeshInfo& theMeshInfo,
3990                  const EGrilleType& type,
3991                  const MED::TIntVector& nbNodeVec)
3992   {
3993     return PGrilleInfo(new TTGrilleInfo
3994                        (theMeshInfo,
3995                         type,
3996                         nbNodeVec));
3997   }
3998
3999   //----------------------------------------------------------------------------
4000   void
4001   TWrapper
4002   ::GetGrilleType(const MED::TMeshInfo& theMeshInfo,
4003                   EGrilleType& theGridType,
4004                   TErr* theErr)
4005   {
4006     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
4007
4008     if (theErr && *theErr < 0)
4009       EXCEPTION(std::runtime_error, " GetGrilleType - aFileWrapper (...)");
4010
4011     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
4012
4013     if (aMeshInfo.myType == eSTRUCTURE) {
4014       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
4015       TValueHolder<EGrilleType, med_grid_type> aGridType(theGridType);
4016       TErr aRet = MEDmeshGridTypeRd(myFile->Id(),
4017                                     &aMeshName,
4018                                     &aGridType);
4019
4020       if (aRet < 0)
4021         EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDmeshGridTypeRd(...)");
4022     }
4023   }
4024
4025   //----------------------------------------------------------------------------
4026   void
4027   TWrapper
4028   ::GetGrilleStruct(const MED::TMeshInfo& theMeshInfo,
4029                     TIntVector& theStruct,
4030                     TErr* theErr)
4031   {
4032     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr);
4033
4034     if (theErr && *theErr < 0)
4035       return;
4036
4037     TErr aRet;
4038     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
4039
4040     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
4041     TValueHolder<TIntVector, med_int> aGridStructure(theStruct);
4042
4043     aRet = MEDmeshGridStructRd(myFile->Id(),
4044                                &aMeshName,
4045                                MED_NO_DT,
4046                                MED_NO_IT,
4047                                &aGridStructure);
4048     if (theErr)
4049       *theErr = aRet;
4050     else if (aRet < 0)
4051       EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDmeshGridStructRd(...)");
4052   }
4053 }