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