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