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