Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MEDWrapper / V2_1 / Wrapper / MED_V2_1_Wrapper.cxx
1 // Copyright (C) 2007-2012  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.
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 //  File   : 
24 //  Author : 
25 //  Module : 
26 //  $Header$
27 //
28 #include "MED_V2_1_Wrapper.hxx"
29 #include "MED_Algorithm.hxx"
30 #include "MED_Utilities.hxx"
31
32 #include "med.hxx"
33 using namespace med_2_1;
34
35 #ifdef _DEBUG_
36 static int MYDEBUG = 0;
37 #else
38 // static int MYDEBUG = 0;
39 #endif
40
41
42
43 namespace MED
44 {
45
46   template<>
47   TInt
48   GetDESCLength<eV2_1>()
49   {
50     return 200;
51   }
52
53   template<>
54   TInt
55   GetIDENTLength<eV2_1>()
56   {
57     return 8;
58   }
59
60   template<>
61   TInt
62   GetLNOMLength<eV2_1>()
63   {
64     return 80;
65   }
66
67   template<>
68   TInt
69   GetNOMLength<eV2_1>()
70   {
71     return 32;
72   }
73
74   template<>
75   TInt
76   GetPNOMLength<eV2_1>()
77   {
78     return 8;
79   }
80
81   template<>
82   void
83   GetVersionRelease<eV2_1>(TInt& majeur, TInt& mineur, TInt& release)
84   {
85     MEDversionDonner(&majeur, &mineur, &release);
86   }
87
88   template<>
89   TInt
90   GetNbConn<eV2_1>(EGeometrieElement typmai,
91                    EEntiteMaillage typent,
92                    TInt mdim)
93   {
94     TInt nsup = 0;
95
96     if(typent == eMAILLE){
97       TInt edim = typmai / 100;
98       if(mdim  == 2 || mdim == 3)
99         if(edim == 1)
100           nsup = 1;
101       
102       if(mdim == 3)
103         if (edim == 2)
104           nsup = 1;
105     }
106
107     return nsup + typmai%100;
108   }
109
110   namespace V2_1
111   {
112
113     //---------------------------------------------------------------
114     class TFile{
115       TFile();
116       TFile(const TFile&);
117       
118     public:
119       TFile(const std::string& theFileName): 
120         myFid(-1), 
121         myCount(0),
122         myFileName(theFileName)
123       {}
124       
125       ~TFile()
126       { 
127         Close();
128       }
129       
130       void
131       Open(EModeAcces theMode, TErr* theErr = NULL)
132       {
133         if(myCount++ == 0){
134           char* aFileName = const_cast<char*>(myFileName.c_str());
135           myFid = MEDouvrir(aFileName,med_mode_acces(theMode));
136         }
137         if(theErr){
138           *theErr = TErr(myFid);
139           INITMSG(MYDEBUG && myFid < 0,"TFile::Open - MED_MODE_ACCES = "<<theMode<<"; myFid = "<<myFid<<std::endl);
140         }else if(myFid < 0)
141           EXCEPTION(std::runtime_error, "TFile - MEDouvrir('"<<myFileName<<"',"<<theMode<<")");
142       }
143
144       const TIdt& Id() const 
145       { 
146         if(myFid < 0)
147           EXCEPTION(std::runtime_error, "TFile - GetFid() < 0");
148         return myFid;
149       }
150
151       void Close()
152       { 
153         if(--myCount == 0)
154           MEDfermer(myFid);
155       }
156
157     protected:
158       std::string myFileName;
159       TInt myCount;
160       TIdt myFid;
161     };
162
163
164     //---------------------------------------------------------------
165     class TFileWrapper
166     {
167       PFile myFile;
168
169     public:
170       TFileWrapper(const PFile& theFile, EModeAcces theMode, TErr* theErr = NULL): 
171         myFile(theFile)
172       {
173         myFile->Open(theMode,theErr);
174       }
175       
176       ~TFileWrapper(){
177         myFile->Close();
178       }
179     };
180
181
182     //---------------------------------------------------------------
183     TVWrapper
184     ::TVWrapper(const std::string& theFileName): 
185       myFile(new TFile(theFileName))
186     {}
187     
188     
189     TInt
190     TVWrapper
191     ::GetNbMeshes(TErr* theErr)
192     {
193       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
194       
195       if(theErr && *theErr < 0)
196         return -1;
197       
198       return MEDnMaa(myFile->Id());
199     }
200     
201     
202     void
203     TVWrapper
204     ::GetMeshInfo(TInt theMeshId, 
205                   TMeshInfo& theInfo,
206                   TErr* theErr)
207     {
208       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
209       
210       if(theErr && *theErr < 0)
211         return;
212       
213       TValueHolder<TString, char> aMeshName(theInfo.myName);
214       TValueHolder<TInt, med_int> aDim(theInfo.mySpaceDim);
215
216       TErr aRet = MEDmaaInfo(myFile->Id(),
217                              theMeshId,
218                              &aMeshName,
219                              &aDim);
220
221       if ( theInfo.mySpaceDim < 1 )
222         theInfo.mySpaceDim = MEDdimLire( myFile->Id(), &aMeshName );
223
224       theInfo.myDim = theInfo.mySpaceDim;
225
226       if(theErr) 
227         *theErr = aRet;
228       else if(aRet < 0)
229         EXCEPTION(std::runtime_error,"GetMeshInfo - MEDmaaInfo(...)");
230     }
231     
232     
233     void 
234     TVWrapper
235     ::SetMeshInfo(const TMeshInfo& theInfo,
236                   EModeAcces theMode,
237                   TErr* theErr)
238     {
239       TFileWrapper aFileWrapper(myFile,theMode,theErr);
240       
241       if(theErr && *theErr < 0)
242         return;
243       
244       TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
245       TValueHolder<TString, char> aMeshName(anInfo.myName);
246       TValueHolder<TInt, med_int> aDim(anInfo.myDim);
247       
248       TErr aRet = MEDmaaCr(myFile->Id(),
249                            &aMeshName,
250                            aDim);
251       
252       if(theErr) 
253         *theErr = aRet;
254       else if(aRet < 0)
255         EXCEPTION(std::runtime_error,"SetMeshInfo - MEDmaaCr(...)");
256     }
257     
258     
259     void
260     TVWrapper
261     ::SetMeshInfo(const TMeshInfo& theInfo,
262                   TErr* theErr)
263     {
264       TErr aRet;
265       SetMeshInfo(theInfo,eECRI,&aRet);
266       
267       if(aRet < 0)
268         SetMeshInfo(theInfo,eREMP,&aRet);
269
270       if(theErr) 
271         *theErr = aRet;
272     }
273     
274     
275     TInt
276     TVWrapper
277     ::GetNbFamilies(const TMeshInfo& theInfo,
278                     TErr* theErr)
279     {
280       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
281       
282       if(theErr && *theErr < 0)
283         return -1;
284       
285       TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
286       TValueHolder<TString, char> aMeshName(anInfo.myName);
287
288       return MEDnFam(myFile->Id(),
289                      &aMeshName,
290                      0,
291                      MED_FAMILLE);
292     }
293     
294     
295     TInt
296     TVWrapper
297     ::GetNbFamAttr(TInt theFamId, 
298                    const TMeshInfo& theInfo,
299                    TErr* theErr)
300     {
301       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
302       
303       if(theErr && *theErr < 0)
304         return -1;
305       
306       TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
307       TValueHolder<TString, char> aMeshName(anInfo.myName);
308
309       return MEDnFam(myFile->Id(),
310                      &aMeshName,
311                      theFamId,
312                      MED_ATTR);
313     }
314     
315     
316     TInt
317     TVWrapper
318     ::GetNbFamGroup(TInt theFamId, 
319                     const TMeshInfo& theInfo,
320                     TErr* theErr)
321     {
322       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
323       
324       if(theErr && *theErr < 0)
325         return -1;
326       
327       TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
328       TValueHolder<TString, char> aMeshName(anInfo.myName);
329
330       return MEDnFam(myFile->Id(),
331                      &aMeshName,
332                      theFamId,
333                      MED_GROUPE);
334     }
335     
336     
337     void
338     TVWrapper
339     ::GetFamilyInfo(TInt theFamId, 
340                     TFamilyInfo& theInfo,
341                     TErr* theErr)
342     {
343       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
344       
345       if(theErr && *theErr < 0)
346         return;
347       
348       TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
349       
350       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
351       TValueHolder<TString, char> aFamilyName(theInfo.myName);
352       TValueHolder<TInt, med_int> aFamilyId(theInfo.myId);
353       TValueHolder<TFamAttr, med_int> anAttrId(theInfo.myAttrId);
354       TValueHolder<TFamAttr, med_int> anAttrVal(theInfo.myAttrVal);
355       TValueHolder<TInt, med_int> aNbAttr(theInfo.myNbAttr);
356       TValueHolder<TString, char> anAttrDesc(theInfo.myAttrDesc);
357       TValueHolder<TInt, med_int> aNbGroup(theInfo.myNbGroup);
358       TValueHolder<TString, char> aGroupNames(theInfo.myGroupNames);
359
360       TErr aRet = MEDfamInfo(myFile->Id(),
361                              &aMeshName,
362                              theFamId,
363                              &aFamilyName,
364                              &aFamilyId,
365                              &anAttrId,
366                              &anAttrVal,
367                              &anAttrDesc,
368                              &aNbAttr,
369                              &aGroupNames,
370                              &aNbGroup);
371       
372       if(theErr) 
373         *theErr = aRet;
374       else if(aRet < 0)
375         EXCEPTION(std::runtime_error,"GetFamilyInfo - MEDfamInfo - "<<
376                   "&aMeshInfo.myName[0] = '"<<&aMeshName<<"'; "<<
377                   "theFamId = "<<theFamId<<"; "<<
378                   "&theInfo.myName[0] = '"<<&aFamilyName<<"'; "<<
379                   "theInfo.myId = "<<theInfo.myId);
380     }
381     
382     
383     void 
384     TVWrapper
385     ::SetFamilyInfo(const TFamilyInfo& theInfo,
386                     EModeAcces theMode,
387                     TErr* theErr)
388     {
389       TFileWrapper aFileWrapper(myFile,theMode,theErr);
390       
391       if(theErr && *theErr < 0)
392         return;
393       
394       TFamilyInfo& anInfo = const_cast<TFamilyInfo&>(theInfo);
395       TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
396       
397       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
398       TValueHolder<TString, char> aFamilyName(anInfo.myName);
399       TValueHolder<TInt, med_int> aFamilyId(anInfo.myId);
400       TValueHolder<TFamAttr, med_int> anAttrId(anInfo.myAttrId);
401       TValueHolder<TFamAttr, med_int> anAttrVal(anInfo.myAttrVal);
402       TValueHolder<TInt, med_int> aNbAttr(anInfo.myNbAttr);
403       TValueHolder<TString, char> anAttrDesc(anInfo.myAttrDesc);
404       TValueHolder<TInt, med_int> aNbGroup(anInfo.myNbGroup);
405       TValueHolder<TString, char> aGroupNames(anInfo.myGroupNames);
406
407       TErr aRet = MEDfamCr(myFile->Id(),
408                            &aMeshName,
409                            &aFamilyName,
410                            aFamilyId,
411                            &anAttrId,
412                            &anAttrVal,
413                            &anAttrDesc,
414                            aNbAttr,
415                            &aGroupNames,
416                            aNbGroup);
417       
418       INITMSG(MYDEBUG && aRet,"TVWrapper::SetFamilyInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
419       
420       if(theErr) 
421         *theErr = aRet;
422       else if(aRet < 0)
423         EXCEPTION(std::runtime_error,"SetFamilyInfo - MEDfamCr(...)");
424     }
425     
426     
427     void 
428     TVWrapper
429     ::SetFamilyInfo(const TFamilyInfo& theInfo,
430                     TErr* theErr)
431     {
432       TErr aRet;
433       SetFamilyInfo(theInfo,eECRI,&aRet);
434       
435       if(aRet < 0)
436         SetFamilyInfo(theInfo,eREMP,&aRet);
437
438       if(theErr) 
439         *theErr = aRet;
440     }
441     
442     
443     TInt
444     TVWrapper
445     ::GetNbNodes(const TMeshInfo& theMeshInfo,
446                  TErr* theErr)
447     {
448       MSG(MYDEBUG,"TVWrapper::GetNbNodes");
449       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
450       
451       if(theErr && *theErr < 0)
452         return -1;
453       
454       TMeshInfo& aMeshInfo = const_cast<TMeshInfo&>(theMeshInfo);
455       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
456       
457       TInt aRet = MEDnEntMaa(myFile->Id(),
458                              &aMeshName,
459                              MED_COOR,
460                              MED_NOEUD,
461                              med_geometrie_element(0),
462                              med_connectivite(0));
463       return aRet;
464     }
465     
466     
467     void 
468     TVWrapper
469     ::GetNodeInfo(TNodeInfo& theInfo,
470                   TErr* theErr)
471     {
472       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
473       
474       if(theErr && *theErr < 0)
475         return;
476       
477       TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
478
479       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
480       TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
481       TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord);
482       TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theInfo.myModeSwitch);
483       TValueHolder<ERepere, med_repere> aSystem(theInfo.mySystem);
484       TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames);
485       TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits);
486       TValueHolder<TString, char> anElemNames(theInfo.myElemNames);
487       TValueHolder<EBooleen, med_booleen> anIsElemNames(theInfo.myIsElemNames);
488       TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum);
489       TValueHolder<EBooleen, med_booleen> anIsElemNum(theInfo.myIsElemNum);
490       TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
491       TValueHolder<TInt, med_int> aNbElem(theInfo.myNbElem);
492
493       TErr aRet = MEDnoeudsLire(myFile->Id(),
494                                 &aMeshName,
495                                 aDim,
496                                 &aCoord,
497                                 aModeSwitch,
498                                 &aSystem,
499                                 &aCoordNames,
500                                 &aCoordUnits,
501                                 &anElemNames,
502                                 &anIsElemNames,
503                                 &anElemNum,
504                                 &anIsElemNum,
505                                 &aFamNum,
506                                 aNbElem);
507
508       if(theErr) 
509         *theErr = aRet;
510       else if(aRet < 0)
511         EXCEPTION(std::runtime_error,"GetNodeInfo - MEDnoeudsLire(...)");
512     }
513     
514     
515     void 
516     TVWrapper
517     ::SetNodeInfo(const MED::TNodeInfo& theInfo,
518                   EModeAcces theMode,
519                   TErr* theErr)
520     {
521       TFileWrapper aFileWrapper(myFile,theMode,theErr);
522       
523       if(theErr && *theErr < 0)
524         return;
525       
526       MED::TNodeInfo& anInfo = const_cast<MED::TNodeInfo&>(theInfo);
527       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
528
529       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
530       TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
531       TValueHolder<TNodeCoord, med_float> aCoord(anInfo.myCoord);
532       TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(anInfo.myModeSwitch);
533       TValueHolder<ERepere, med_repere> aSystem(anInfo.mySystem);
534       TValueHolder<TString, char> aCoordNames(anInfo.myCoordNames);
535       TValueHolder<TString, char> aCoordUnits(anInfo.myCoordUnits);
536       TValueHolder<TString, char> anElemNames(anInfo.myElemNames);
537       TValueHolder<EBooleen, med_booleen> anIsElemNames(anInfo.myIsElemNames);
538       TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
539       TValueHolder<EBooleen, med_booleen> anIsElemNum(anInfo.myIsElemNum);
540       TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum);
541       TValueHolder<TInt, med_int> aNbElem(anInfo.myNbElem);
542
543       TErr aRet = MEDnoeudsEcr(myFile->Id(),
544                                &aMeshName,
545                                aDim,
546                                &aCoord,
547                                aModeSwitch,
548                                aSystem,
549                                &aCoordNames,
550                                &aCoordUnits,
551                                &anElemNames,
552                                anIsElemNames,
553                                &anElemNum,
554                                anIsElemNum,
555                                &aFamNum,
556                                aNbElem,
557                                MED_REMP);
558       if(theErr) 
559         *theErr = aRet;
560       else if(aRet < 0)
561         EXCEPTION(std::runtime_error,"SetNodeInfo - MEDnoeudsEcr(...)");
562     }
563     
564     
565     void 
566     TVWrapper
567     ::SetNodeInfo(const MED::TNodeInfo& theInfo,
568                   TErr* theErr)
569     {
570       TErr aRet;
571       SetNodeInfo(theInfo,eECRI,&aRet);
572       
573       if(aRet < 0)
574         SetNodeInfo(theInfo,eREMP,&aRet);
575
576       if(theErr) 
577         *theErr = aRet;
578     }
579     
580     
581     TEntityInfo
582     TVWrapper
583     ::GetEntityInfo(const TMeshInfo& theMeshInfo,
584                     EConnectivite theConnMode,
585                     TErr* theErr)
586     {
587       TEntityInfo anInfo;
588       
589       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
590       
591       if(theErr && *theErr < 0)
592         return anInfo;
593       
594       TInt aNbElem = GetNbNodes(theMeshInfo);
595       if(aNbElem > 0){
596         anInfo[eNOEUD][ePOINT1] = aNbElem;
597         const TEntity2GeomSet& anEntity2GeomSet = GetEntity2GeomSet();
598         TEntity2GeomSet::const_iterator anIter = anEntity2GeomSet.begin();
599         TEntity2GeomSet::const_iterator anIterEnd = anEntity2GeomSet.end();
600         for(; anIter != anIterEnd; anIter++){
601           const EEntiteMaillage& anEntity = anIter->first;
602           const TGeomSet& aGeomSet = anIter->second;
603           TGeomSet::const_iterator anIter2 = aGeomSet.begin();
604           TGeomSet::const_iterator anIterEnd2 = aGeomSet.end();
605           for(; anIter2 != anIterEnd2; anIter2++){
606             const EGeometrieElement& aGeom = *anIter2;
607             aNbElem = GetNbCells(theMeshInfo,anEntity,aGeom,theConnMode,theErr);
608             if(aNbElem > 0)
609               anInfo[anEntity][aGeom] = aNbElem;
610           }
611         }
612       }
613       return anInfo;
614     }
615     
616     
617     TInt
618     TVWrapper
619     ::GetNbCells(const MED::TMeshInfo& theMeshInfo, 
620                  EEntiteMaillage theEntity, 
621                  EGeometrieElement theGeom, 
622                  EConnectivite theConnMode,
623                  TErr* theErr)
624     {
625       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
626       
627       if(theErr && *theErr < 0)
628         return -1;
629       
630       MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
631       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
632       
633       return MEDnEntMaa(myFile->Id(),
634                         &aMeshName,
635                         MED_CONN,
636                         med_entite_maillage(theEntity),
637                         med_geometrie_element(theGeom),
638                         med_connectivite(theConnMode)); 
639     }
640     
641     
642     void 
643     TVWrapper
644     ::GetCellInfo(MED::TCellInfo& theInfo,
645                   TErr* theErr)
646     {
647       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
648
649       if(theErr && *theErr < 0)
650         return;
651       
652       MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
653       TInt aNbElem = theInfo.myElemNum->size();
654
655       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
656       TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
657       TValueHolder<TElemNum, med_int> aConn(theInfo.myConn);
658       TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theInfo.myModeSwitch);
659       TValueHolder<TString, char> anElemNames(theInfo.myElemNames);
660       TValueHolder<EBooleen, med_booleen> anIsElemNames(theInfo.myIsElemNames);
661       TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum);
662       TValueHolder<EBooleen, med_booleen> anIsElemNum(theInfo.myIsElemNum);
663       TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
664       TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theInfo.myEntity);
665       TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(theInfo.myGeom);
666       TValueHolder<EConnectivite, med_connectivite> aConnMode(theInfo.myConnMode);
667
668       TErr aRet;
669       aRet = MEDelementsLire(myFile->Id(),
670                              &aMeshName,
671                              aDim,
672                              &aConn,
673                              aModeSwitch,
674                              &anElemNames,
675                              &anIsElemNames,
676                              &anElemNum,
677                              &anIsElemNum,
678                              &aFamNum,
679                              aNbElem,
680                              anEntity,
681                              aGeom,
682                              aConnMode);
683
684       if(theErr) 
685         *theErr = aRet;
686       else if(aRet < 0)
687         EXCEPTION(std::runtime_error,"GetCellInfo - MEDelementsLire(...)");
688     }
689     
690     
691     void 
692     TVWrapper
693     ::SetCellInfo(const MED::TCellInfo& theInfo,
694                   EModeAcces theMode,
695                   TErr* theErr)
696     {
697       TFileWrapper aFileWrapper(myFile,theMode,theErr);
698       
699       if(theErr && *theErr < 0)
700         return;
701
702       MED::TCellInfo& anInfo = const_cast<MED::TCellInfo&>(theInfo);
703       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
704
705       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
706       TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
707       TValueHolder<TElemNum, med_int> aConn(anInfo.myConn);
708       TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(anInfo.myModeSwitch);
709       TValueHolder<TString, char> anElemNames(anInfo.myElemNames);
710       TValueHolder<EBooleen, med_booleen> anIsElemNames(anInfo.myIsElemNames);
711       TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
712       TValueHolder<EBooleen, med_booleen> anIsElemNum(anInfo.myIsElemNum);
713       TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum);
714       TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(anInfo.myEntity);
715       TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(anInfo.myGeom);
716       TValueHolder<EConnectivite, med_connectivite> aConnMode(anInfo.myConnMode);
717
718       TErr aRet;
719       aRet = MEDelementsEcr(myFile->Id(),
720                             &aMeshName,
721                             aDim,
722                             &aConn,
723                             aModeSwitch,
724                             &anElemNames,
725                             anIsElemNames,
726                             &anElemNum,
727                             anIsElemNum,
728                             &aFamNum,
729                             anInfo.myNbElem,
730                             anEntity,
731                             aGeom,
732                             aConnMode,
733                             MED_REMP);
734       
735       if(theErr) 
736         *theErr = aRet;
737       else if(aRet < 0)
738         EXCEPTION(std::runtime_error,"GetCellInfo - MEDelementsLire(...)");
739     }
740     
741
742     void
743     TVWrapper
744     ::SetCellInfo(const MED::TCellInfo& theInfo,
745                   TErr* theErr)
746     {
747       TErr aRet;
748       SetCellInfo(theInfo,eECRI,&aRet);
749       
750       if(aRet < 0)
751         SetCellInfo(theInfo,eREMP,&aRet);
752
753       if(theErr) 
754         *theErr = aRet;
755     }
756     
757
758     TInt
759     TVWrapper
760     ::GetNbFields(TErr* theErr)
761     {
762       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
763       
764       if(theErr && *theErr < 0)
765         return -1;
766       
767       return MEDnChamp(myFile->Id(),0);
768     }
769     
770     
771     TInt
772     TVWrapper
773     ::GetNbComp(TInt theFieldId,
774                 TErr* theErr)
775     {
776       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
777       
778       if(theErr && *theErr < 0)
779         return -1;
780       
781       return MEDnChamp(myFile->Id(),theFieldId);
782     }
783     
784     
785     void 
786     TVWrapper
787     ::GetFieldInfo(TInt theFieldId, 
788                    MED::TFieldInfo& theInfo,
789                    TErr* theErr)
790     {
791       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
792       
793       if(theErr && *theErr < 0)
794         return;
795       
796       TString aFieldName(256); // Protect from memory problems with too long names
797       TValueHolder<ETypeChamp, med_type_champ> aType(theInfo.myType);
798       TValueHolder<TString, char> aCompNames(theInfo.myCompNames);
799       TValueHolder<TString, char> anUnitNames(theInfo.myUnitNames);
800
801       TErr aRet;
802       aRet = MEDchampInfo(myFile->Id(),
803                           theFieldId,
804                           &aFieldName[0],
805                           &aType,
806                           &aCompNames,
807                           &anUnitNames,
808                           theInfo.myNbComp);
809
810       theInfo.SetName(aFieldName);
811
812       if(theErr) 
813         *theErr = aRet;
814       else if(aRet < 0)
815         EXCEPTION(std::runtime_error,"GetFieldInfo - MEDchampInfo(...)");
816     }
817     
818     
819     void
820     TVWrapper
821     ::SetFieldInfo(const MED::TFieldInfo& theInfo,
822                    EModeAcces theMode,
823                    TErr* theErr)
824     {
825       TFileWrapper aFileWrapper(myFile,theMode,theErr);
826       
827       if(theErr && *theErr < 0)
828         return;
829       
830       MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
831       
832       TValueHolder<TString, char> aFieldName(anInfo.myName);
833       TValueHolder<ETypeChamp, med_type_champ> aType(anInfo.myType);
834       TValueHolder<TString, char> aCompNames(anInfo.myCompNames);
835       TValueHolder<TString, char> anUnitNames(anInfo.myUnitNames);
836
837       TErr aRet;
838       aRet = MEDchampCr(myFile->Id(),
839                         &aFieldName,
840                         aType,
841                         &aCompNames,
842                         &anUnitNames,
843                         anInfo.myNbComp);
844
845       if(theErr) 
846         *theErr = aRet;
847       else if(aRet < 0)
848         EXCEPTION(std::runtime_error,"SetFieldInfo - MEDchampCr(...)");
849     }
850     
851     
852     void
853     TVWrapper
854     ::SetFieldInfo(const MED::TFieldInfo& theInfo,
855                    TErr* theErr)
856     {
857       try{
858
859         TErr aRet;
860         SetFieldInfo(theInfo,eECRI,&aRet);
861       
862         if(aRet < 0)
863           SetFieldInfo(theInfo,eREMP,&aRet);
864
865         if(theErr) 
866           *theErr = aRet;
867
868       }catch(const std::exception& theExc){
869         EXCEPTION(std::runtime_error,"SetFieldInfo(...)"<<std::endl<<
870                   theExc.what());
871       }catch(...){
872         throw;
873       }
874     }
875     
876     //-----------------------------------------------------------------
877     TInt
878     TVWrapper
879     ::GetNbProfiles(TErr* theErr)
880     {
881       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
882       
883       if(theErr && *theErr < 0)
884         return -1;
885       
886       return MEDnProfil(myFile->Id());
887     }
888
889
890     TProfileInfo::TInfo
891     TVWrapper
892     ::GetProfilePreInfo(TInt theId, 
893                         TErr* theErr)
894     {
895       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
896
897       if(theErr && *theErr < 0)
898         return TProfileInfo::TInfo("",-1);
899       
900       med_int aSize = -1;
901       TVector<char> aName(GetNOMLength<eV2_1>()+1);
902
903       TErr aRet;
904       aRet = MEDprofilInfo(myFile->Id(),
905                            theId,
906                            &aName[0],
907                            &aSize);
908       if(theErr) 
909         *theErr = aRet;
910       else if(aRet < 0)
911         EXCEPTION(std::runtime_error,"GetProfilePreInfo - MEDprofilInfo(...)");
912       
913       return TProfileInfo::TInfo(&aName[0],aSize);
914     }
915
916
917     void
918     TVWrapper
919     ::GetProfileInfo(TInt theId, 
920                      TProfileInfo& theInfo,
921                      TErr* theErr)
922     {
923       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
924       
925       if(theErr && *theErr < 0)
926         return;
927       
928       TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum);
929       TValueHolder<TString, char> aProfileName(theInfo.myName);
930
931       TErr aRet;
932       aRet = MEDprofilLire(myFile->Id(),
933                            &anElemNum,
934                            &aProfileName);
935       if(theErr) 
936         *theErr = aRet;
937       else if(aRet < 0)
938         EXCEPTION(std::runtime_error,"GetProfileInfo - MEDprofilLire(...)");
939     }
940
941     void
942     TVWrapper
943     ::SetProfileInfo(const TProfileInfo& theInfo,
944                      EModeAcces          theMode,
945                      TErr*               theErr)
946     {
947       TFileWrapper aFileWrapper(myFile,theMode,theErr);
948       
949       if(theErr && *theErr < 0)
950         return;
951       
952       TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo);
953       TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
954       TValueHolder<TString, char>     aProfileName(anInfo.myName);
955
956       TErr aRet;
957       aRet = MEDprofilEcr(myFile->Id(),      // descripteur du fichier.
958                           &anElemNum,        // tableau de valeurs du profil.
959                           theInfo.GetSize(), // taille du profil.
960                           &aProfileName);    // nom profil.
961       if(theErr)
962         *theErr = aRet;
963       else if(aRet < 0)
964         EXCEPTION(std::runtime_error,"SetProfileInfo - MEDprofilEcr(...)");
965     }
966
967     void
968     TVWrapper
969     ::SetProfileInfo(const TProfileInfo& theInfo,
970                      TErr* theErr)
971     {
972       TErr aRet;
973       SetProfileInfo(theInfo,eECRI,&aRet);
974       
975       if(aRet < 0)
976         SetProfileInfo(theInfo,eREMP,&aRet);
977
978       if(theErr) 
979         *theErr = aRet;
980     }
981
982     //-----------------------------------------------------------------
983     TInt
984     TVWrapper
985     ::GetNbTimeStamps(const MED::TFieldInfo& theInfo, 
986                       const MED::TEntityInfo& theEntityInfo,
987                       EEntiteMaillage& theEntity,
988                       TGeom2Size& theGeom2Size,
989                       TErr* theErr)
990     {
991       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
992       
993       if(theErr){
994         if(theEntityInfo.empty())
995           *theErr = -1;
996         if(*theErr < 0)
997           return -1;
998       }else if(theEntityInfo.empty()) 
999         EXCEPTION(std::runtime_error,"GetNbTimeStamps - There is no any Entity on the Mesh");
1000
1001       bool anIsPerformAdditionalCheck = GetNbMeshes() > 1;
1002 #ifdef _DEBUG_
1003       static bool anIsCheckOnlyFirstTimeStamp = false;
1004 #else
1005       static bool anIsCheckOnlyFirstTimeStamp = true;
1006 #endif
1007
1008       theGeom2Size.clear();
1009       TInt aNbTimeStamps = 0;
1010       TIdt anId = myFile->Id();
1011
1012       MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
1013       TValueHolder<TString, char> aFieldName(anInfo.myName);
1014       MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo;
1015
1016       TEntityInfo::const_iterator anIter = theEntityInfo.begin();
1017       for(; anIter != theEntityInfo.end(); anIter++){
1018         med_entite_maillage anEntity = med_entite_maillage(anIter->first);
1019         const TGeom2Size& aGeom2Size = anIter->second;
1020         TGeom2Size::const_iterator anGeomIter = aGeom2Size.begin();
1021         for(; anGeomIter != aGeom2Size.end(); anGeomIter++){
1022           med_geometrie_element aGeom = med_geometrie_element(anGeomIter->first);
1023           TInt aNbStamps = MEDnPasdetemps(anId,
1024                                           &aFieldName,
1025                                           anEntity,
1026                                           aGeom);
1027           bool anIsSatisfied = aNbStamps > 0;
1028           if(anIsSatisfied){
1029             INITMSG(MYDEBUG,
1030                     "GetNbTimeStamps aNbTimeStamps = "<<aNbStamps<<
1031                     "; aGeom = "<<aGeom<<"; anEntity = "<<anEntity<<"\n");
1032             if(anIsPerformAdditionalCheck){
1033               TInt iTimeStampEnd = anIsCheckOnlyFirstTimeStamp? 1: aNbStamps;
1034               for(TInt iTimeStamp = 1; iTimeStamp <= iTimeStampEnd; iTimeStamp++){
1035                 TVector<char> aMeshName(GetNOMLength<eV2_1>()+1);
1036                 TVector<char> aDtUnit(GetPNOMLength<eV2_1>()+1);
1037                 med_int aNbGauss;
1038                 med_int aNumDt;
1039                 med_int aNumOrd;
1040                 med_float aDt;
1041                 TErr aRet = MEDpasdetempsInfo(anId,
1042                                               &aFieldName,
1043                                               anEntity,
1044                                               aGeom,
1045                                               iTimeStamp, 
1046                                               &aMeshName[0],
1047                                               &aNbGauss,
1048                                               &aNumDt,  
1049                                               &aDtUnit[0],
1050                                               &aDt, 
1051                                               &aNumOrd);
1052                 
1053                 anIsSatisfied = (aRet == 0 && (!strcmp(&aMeshName[0],&aMeshInfo.myName[0])));
1054                 if(!anIsSatisfied){
1055                   INITMSG(MYDEBUG,
1056                           "GetNbTimeStamps aMeshName = '"<<&aMeshName[0]<<"' != "<<
1057                           "; aMeshInfo.myName = '"<<&aMeshInfo.myName[0]<<"'\n");
1058                   break;
1059                 }
1060               }
1061             }
1062           }
1063           if(anIsSatisfied){
1064             theGeom2Size[EGeometrieElement(aGeom)] = anGeomIter->second;
1065             theEntity = EEntiteMaillage(anEntity);
1066             aNbTimeStamps = aNbStamps;
1067           }
1068         }
1069         if(!theGeom2Size.empty()) 
1070           break;
1071       }
1072       return aNbTimeStamps;
1073     }
1074     
1075     
1076     void
1077     TVWrapper
1078     ::GetTimeStampInfo(TInt theTimeStampId, 
1079                        MED::TTimeStampInfo& theInfo,
1080                        TErr* theErr)
1081     {
1082       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
1083       
1084       const TGeom2Size& aGeom2Size = theInfo.myGeom2Size;     
1085
1086       if(theErr){
1087         if(aGeom2Size.empty())
1088           *theErr = -1;
1089         if(*theErr < 0)
1090           return;
1091       }else if(aGeom2Size.empty())
1092         EXCEPTION(std::runtime_error,"GetTimeStampInfo - There is no any cell");
1093       
1094       MED::TFieldInfo& aFieldInfo = *theInfo.myFieldInfo;
1095       MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
1096       
1097       TValueHolder<TString, char> aFieldName(aFieldInfo.myName);
1098       TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theInfo.myEntity);
1099       TValueHolder<TInt, med_int> aNumDt(theInfo.myNumDt);
1100       TValueHolder<TInt, med_int> aNumOrd(theInfo.myNumOrd);
1101       TValueHolder<TString, char> anUnitDt(theInfo.myUnitDt);
1102       TValueHolder<TFloat, med_float> aDt(theInfo.myDt);
1103       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1104
1105       TGeom2NbGauss& aGeom2NbGauss = theInfo.myGeom2NbGauss;
1106
1107       TGeom2Size::const_iterator anIter = aGeom2Size.begin();
1108       for(; anIter != aGeom2Size.end(); anIter++){
1109         const EGeometrieElement& aGeom = anIter->first;
1110         med_int aNbGauss = -1;
1111
1112         TErr aRet;
1113         aRet = MEDpasdetempsInfo(myFile->Id(),
1114                                  &aFieldName,
1115                                  anEntity,
1116                                  med_geometrie_element(aGeom),
1117                                  theTimeStampId,
1118                                  &aMeshName,
1119                                  &aNbGauss,
1120                                  &aNumDt,
1121                                  &anUnitDt,
1122                                  &aDt,
1123                                  &aNumOrd);
1124         
1125         
1126         static TInt MAX_NB_GAUSS_POINTS = 32;
1127         if(aNbGauss <= 0 || aNbGauss > MAX_NB_GAUSS_POINTS)
1128           aNbGauss = 1;
1129
1130         aGeom2NbGauss[aGeom] = aNbGauss;
1131         
1132         if(theErr) 
1133           *theErr = aRet;
1134         else if(aRet < 0)
1135           EXCEPTION(std::runtime_error,"GetTimeStampInfo - MEDpasdetempsInfo(...)");
1136       }
1137     }
1138     
1139
1140     void 
1141     TVWrapper
1142     ::GetTimeStampValue(const PTimeStampValueBase& theTimeStampValue,
1143                         const TMKey2Profile& theMKey2Profile,
1144                         const TKey2Gauss& theKey2Gauss,
1145                         TErr* theErr)
1146     {
1147       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
1148       
1149       if(theErr && *theErr < 0)
1150         return;
1151       
1152       TIdt anId = myFile->Id();
1153       
1154       TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theTimeStampValue->myModeSwitch);
1155       MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile;
1156
1157       MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo;
1158       TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(aTimeStampInfo->myEntity);
1159       TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt);
1160       TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd);
1161
1162       MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo;
1163       TValueHolder<TString, char> aFieldName(aFieldInfo->myName);
1164
1165       MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo;
1166       TValueHolder<TString, char> aMeshName(aMeshInfo->myName);
1167       
1168       MED::TKey2Profile aKey2Profile = boost::get<1>(theMKey2Profile);
1169       TVector<char> aProfileName(GetNOMLength<eV2_1>()+1);
1170
1171       TGeom2Size& aGeom2Size = aTimeStampInfo->myGeom2Size;
1172       TGeom2Size::iterator anIter = aGeom2Size.begin();
1173       for(; anIter != aGeom2Size.end(); anIter++){
1174         EGeometrieElement aGeom = anIter->first;
1175         TInt aNbElem = anIter->second;
1176
1177         TInt aNbVal = MEDnVal(anId,
1178                               &aFieldName,
1179                               anEntity,
1180                               med_geometrie_element(aGeom),
1181                               aNumDt,
1182                               aNumOrd);
1183         if(aNbVal <= 0){
1184           if(theErr){
1185             *theErr = -1;
1186             return;
1187           }
1188           EXCEPTION(std::runtime_error,"GetTimeStampValue - MEDnVal(...) - aNbVal == "<<aNbVal<<" <= 0");
1189         }
1190         
1191         TInt aNbGauss = aTimeStampInfo->GetNbGauss(aGeom);
1192         TInt aNbComp = aFieldInfo->myNbComp;
1193         TInt aNbValue = aNbVal / aNbGauss;
1194         theTimeStampValue->AllocateValue(aGeom,
1195                                          aNbValue,
1196                                          aNbGauss,
1197                                          aNbComp);
1198         TInt aValueSize = theTimeStampValue->GetValueSize(aGeom);
1199
1200         INITMSG(MYDEBUG,
1201                 "TVWrapper::GetTimeStampValue - aGeom = "<<aGeom<<
1202                 "; aNbVal = "<<aNbVal<<
1203                 "; aNbValue = "<<aNbValue<<
1204                 "; aNbGauss = "<<aNbGauss<<
1205                 "; aNbComp = "<<aNbComp<<
1206                 std::endl);
1207
1208         TErr aRet = MEDchampLire(anId,
1209                                  &aMeshName,
1210                                  &aFieldName,
1211                                  theTimeStampValue->GetValuePtr(aGeom),
1212                                  aModeSwitch,
1213                                  MED_ALL,
1214                                  &aProfileName[0],
1215                                  anEntity,
1216                                  med_geometrie_element(aGeom),
1217                                  aNumDt,
1218                                  aNumOrd);
1219         if(aRet < 0){
1220           if(theErr){
1221             *theErr = aRet;
1222             return;
1223           }
1224           EXCEPTION(std::runtime_error,"GetTimeStampValue - MEDchampLire(...)");
1225         }
1226
1227         MED::PProfileInfo aProfileInfo;
1228         if(strcmp(&aProfileName[0],"") != 0){
1229           MED::TKey2Profile::const_iterator anIter = aKey2Profile.find(&aProfileName[0]);
1230           if(anIter != aKey2Profile.end()){
1231             aProfileInfo = anIter->second;
1232             aGeom2Profile[aGeom] = aProfileInfo;
1233           }
1234         }
1235           
1236         if(aProfileInfo && aProfileInfo->IsPresent()){
1237           TInt aNbSubElem = aProfileInfo->GetSize();
1238           TInt aProfileSize = aNbSubElem*aNbComp*aNbGauss;
1239           if(aProfileSize > aValueSize){
1240             if(theErr){
1241               *theErr = -1;
1242               return;
1243             }
1244             EXCEPTION(std::runtime_error,
1245                       "GetTimeStampValue - aProfileSize("<<aProfileSize<<
1246                       ") != aValueSize("<<aValueSize<<
1247                       "); aNbVal = "<<aNbVal<<
1248                       "; anEntity = "<<anEntity<<
1249                       "; aGeom = "<<aGeom<<
1250                       "; aNbElem = "<<aNbElem<<
1251                       "; aNbSubElem = "<<aNbSubElem<<
1252                       "; aNbComp = "<<aNbComp<<
1253                       "; aNbGauss = "<<aNbGauss<<
1254                       "");
1255           }else{
1256             if(aNbElem != aNbValue){
1257               if(theErr){
1258                 *theErr = -1;
1259                 return;
1260               }
1261               EXCEPTION(std::runtime_error,
1262                         "GetTimeStampValue - aNbElem("<<aNbElem<<
1263                         ") != aNbValue("<<aNbValue<<
1264                         "); aNbVal = "<<aNbVal<<
1265                         "; anEntity = "<<anEntity<<
1266                         "; aGeom = "<<aGeom<<
1267                         "; aNbElem = "<<aNbElem<<
1268                         "; aNbComp = "<<aNbComp<<
1269                         "; aNbGauss = "<<aNbGauss<<
1270                         "");
1271             }
1272           }
1273         }
1274       }
1275     }
1276     
1277     
1278     void
1279     TVWrapper
1280     ::SetTimeStampValue(const MED::PTimeStampValueBase& theTimeStampValue,
1281                         EModeAcces theMode,
1282                         TErr* theErr)
1283     {
1284       TFileWrapper aFileWrapper(myFile,theMode,theErr);
1285       
1286       if(theErr && *theErr < 0)
1287         return;
1288       
1289       TErr aRet;
1290       TIdt anId = myFile->Id();
1291       
1292       TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theTimeStampValue->myModeSwitch);
1293       MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile;
1294
1295       MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo;
1296       TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(aTimeStampInfo->myEntity);
1297       TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt);
1298       TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd);
1299       TValueHolder<TString, char> anUnitDt(aTimeStampInfo->myUnitDt);
1300       TValueHolder<TFloat, med_float> aDt(aTimeStampInfo->myDt);
1301
1302       MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo;
1303       TValueHolder<TString, char> aFieldName(aFieldInfo->myName);
1304
1305       MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo;
1306       TValueHolder<TString, char> aMeshName(aMeshInfo->myName);
1307       
1308       const TGeomSet& aGeomSet = theTimeStampValue->myGeomSet;
1309       TGeomSet::const_iterator anIter = aGeomSet.begin();
1310       for(; anIter != aGeomSet.end(); anIter++){
1311         EGeometrieElement aGeom = *anIter;
1312
1313         TVector<char> aProfileName(GetNOMLength<eV2_1>()+1);
1314         MED::TGeom2Profile::iterator aProfileIter = aGeom2Profile.find(aGeom);
1315         if(aProfileIter != aGeom2Profile.end()){
1316           MED::TProfileInfo& aProfileInfo = aProfileIter->second;
1317           aProfileName = aProfileInfo.myName;
1318         }
1319
1320         med_int aNbGauss = aTimeStampInfo->GetNbGauss(aGeom);
1321         med_int aNbVal = theTimeStampValue->GetNbVal(aGeom);
1322         
1323         aRet = MEDchampEcr(anId,
1324                            &aMeshName,
1325                            &aFieldName,
1326                            theTimeStampValue->GetValuePtr(aGeom),
1327                            aModeSwitch,
1328                            aNbVal,
1329                            aNbGauss,
1330                            MED_ALL,
1331                            &aProfileName[0],
1332                            MED_ECRI, 
1333                            anEntity,
1334                            med_geometrie_element(aGeom),
1335                            aNumDt,
1336                            &anUnitDt,
1337                            aDt,
1338                            aNumOrd);
1339         if(aRet < 0){
1340           if(theErr){
1341             *theErr = aRet;
1342             break;
1343           }
1344           EXCEPTION(std::runtime_error,"SetTimeStampValue - MEDchampEcr(...)");
1345         }
1346         
1347       }
1348       
1349       INITMSG(MYDEBUG,"TVWrapper::SetTimeStampValue - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
1350     }
1351
1352     
1353     void
1354     TVWrapper
1355     ::SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue,
1356                         TErr* theErr)
1357     {
1358       TErr aRet;
1359       SetTimeStampValue(theTimeStampValue,eECRI,&aRet);
1360       
1361       if(aRet < 0)
1362         SetTimeStampValue(theTimeStampValue,eREMP,&aRet);
1363
1364       if(theErr) 
1365         *theErr = aRet;
1366     }
1367     
1368   }
1369 }