Back to index

salome-med  6.5.0
MED_V2_1_Wrapper.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : 
00024 //  Author : 
00025 //  Module : 
00026 //  $Header: /home/server/cvs/MED/MED_SRC/src/MEDWrapper/V2_1/Wrapper/MED_V2_1_Wrapper.cxx,v 1.7.2.2.6.4.10.1 2012-04-13 08:48:45 vsr Exp $
00027 //
00028 #include "MED_V2_1_Wrapper.hxx"
00029 #include "MED_Algorithm.hxx"
00030 #include "MED_Utilities.hxx"
00031 
00032 #include "med.hxx"
00033 using namespace med_2_1;
00034 
00035 #ifdef _DEBUG_
00036 static int MYDEBUG = 0;
00037 #else
00038 // static int MYDEBUG = 0;
00039 #endif
00040 
00041 
00042 
00043 namespace MED
00044 {
00045 
00046   template<>
00047   TInt
00048   GetDESCLength<eV2_1>()
00049   {
00050     return 200;
00051   }
00052 
00053   template<>
00054   TInt
00055   GetIDENTLength<eV2_1>()
00056   {
00057     return 8;
00058   }
00059 
00060   template<>
00061   TInt
00062   GetLNOMLength<eV2_1>()
00063   {
00064     return 80;
00065   }
00066 
00067   template<>
00068   TInt
00069   GetNOMLength<eV2_1>()
00070   {
00071     return 32;
00072   }
00073 
00074   template<>
00075   TInt
00076   GetPNOMLength<eV2_1>()
00077   {
00078     return 8;
00079   }
00080 
00081   template<>
00082   void
00083   GetVersionRelease<eV2_1>(TInt& majeur, TInt& mineur, TInt& release)
00084   {
00085     MEDversionDonner(&majeur, &mineur, &release);
00086   }
00087 
00088   template<>
00089   TInt
00090   GetNbConn<eV2_1>(EGeometrieElement typmai,
00091                    EEntiteMaillage typent,
00092                    TInt mdim)
00093   {
00094     TInt nsup = 0;
00095 
00096     if(typent == eMAILLE){
00097       TInt edim = typmai / 100;
00098       if(mdim  == 2 || mdim == 3)
00099         if(edim == 1)
00100           nsup = 1;
00101       
00102       if(mdim == 3)
00103         if (edim == 2)
00104           nsup = 1;
00105     }
00106 
00107     return nsup + typmai%100;
00108   }
00109 
00110   namespace V2_1
00111   {
00112 
00113     //---------------------------------------------------------------
00114     class TFile{
00115       TFile();
00116       TFile(const TFile&);
00117       
00118     public:
00119       TFile(const std::string& theFileName): 
00120         myFid(-1), 
00121         myCount(0),
00122         myFileName(theFileName)
00123       {}
00124       
00125       ~TFile()
00126       { 
00127         Close();
00128       }
00129       
00130       void
00131       Open(EModeAcces theMode, TErr* theErr = NULL)
00132       {
00133         if(myCount++ == 0){
00134           char* aFileName = const_cast<char*>(myFileName.c_str());
00135           myFid = MEDouvrir(aFileName,med_mode_acces(theMode));
00136         }
00137         if(theErr){
00138           *theErr = TErr(myFid);
00139           INITMSG(MYDEBUG && myFid < 0,"TFile::Open - MED_MODE_ACCES = "<<theMode<<"; myFid = "<<myFid<<std::endl);
00140         }else if(myFid < 0)
00141           EXCEPTION(std::runtime_error, "TFile - MEDouvrir('"<<myFileName<<"',"<<theMode<<")");
00142       }
00143 
00144       const TIdt& Id() const 
00145       { 
00146         if(myFid < 0)
00147           EXCEPTION(std::runtime_error, "TFile - GetFid() < 0");
00148         return myFid;
00149       }
00150 
00151       void Close()
00152       { 
00153         if(--myCount == 0)
00154           MEDfermer(myFid);
00155       }
00156 
00157     protected:
00158       std::string myFileName;
00159       TInt myCount;
00160       TIdt myFid;
00161     };
00162 
00163 
00164     //---------------------------------------------------------------
00165     class TFileWrapper
00166     {
00167       PFile myFile;
00168 
00169     public:
00170       TFileWrapper(const PFile& theFile, EModeAcces theMode, TErr* theErr = NULL): 
00171         myFile(theFile)
00172       {
00173         myFile->Open(theMode,theErr);
00174       }
00175       
00176       ~TFileWrapper(){
00177         myFile->Close();
00178       }
00179     };
00180 
00181 
00182     //---------------------------------------------------------------
00183     TVWrapper
00184     ::TVWrapper(const std::string& theFileName): 
00185       myFile(new TFile(theFileName))
00186     {}
00187     
00188     
00189     TInt
00190     TVWrapper
00191     ::GetNbMeshes(TErr* theErr)
00192     {
00193       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00194       
00195       if(theErr && *theErr < 0)
00196         return -1;
00197       
00198       return MEDnMaa(myFile->Id());
00199     }
00200     
00201     
00202     void
00203     TVWrapper
00204     ::GetMeshInfo(TInt theMeshId, 
00205                   TMeshInfo& theInfo,
00206                   TErr* theErr)
00207     {
00208       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00209       
00210       if(theErr && *theErr < 0)
00211         return;
00212       
00213       TValueHolder<TString, char> aMeshName(theInfo.myName);
00214       TValueHolder<TInt, med_int> aDim(theInfo.mySpaceDim);
00215 
00216       TErr aRet = MEDmaaInfo(myFile->Id(),
00217                              theMeshId,
00218                              &aMeshName,
00219                              &aDim);
00220 
00221       if ( theInfo.mySpaceDim < 1 )
00222         theInfo.mySpaceDim = MEDdimLire( myFile->Id(), &aMeshName );
00223 
00224       theInfo.myDim = theInfo.mySpaceDim;
00225 
00226       if(theErr) 
00227         *theErr = aRet;
00228       else if(aRet < 0)
00229         EXCEPTION(std::runtime_error,"GetMeshInfo - MEDmaaInfo(...)");
00230     }
00231     
00232     
00233     void 
00234     TVWrapper
00235     ::SetMeshInfo(const TMeshInfo& theInfo,
00236                   EModeAcces theMode,
00237                   TErr* theErr)
00238     {
00239       TFileWrapper aFileWrapper(myFile,theMode,theErr);
00240       
00241       if(theErr && *theErr < 0)
00242         return;
00243       
00244       TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
00245       TValueHolder<TString, char> aMeshName(anInfo.myName);
00246       TValueHolder<TInt, med_int> aDim(anInfo.myDim);
00247       
00248       TErr aRet = MEDmaaCr(myFile->Id(),
00249                            &aMeshName,
00250                            aDim);
00251       
00252       if(theErr) 
00253         *theErr = aRet;
00254       else if(aRet < 0)
00255         EXCEPTION(std::runtime_error,"SetMeshInfo - MEDmaaCr(...)");
00256     }
00257     
00258     
00259     void
00260     TVWrapper
00261     ::SetMeshInfo(const TMeshInfo& theInfo,
00262                   TErr* theErr)
00263     {
00264       TErr aRet;
00265       SetMeshInfo(theInfo,eECRI,&aRet);
00266       
00267       if(aRet < 0)
00268         SetMeshInfo(theInfo,eREMP,&aRet);
00269 
00270       if(theErr) 
00271         *theErr = aRet;
00272     }
00273     
00274     
00275     TInt
00276     TVWrapper
00277     ::GetNbFamilies(const TMeshInfo& theInfo,
00278                     TErr* theErr)
00279     {
00280       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00281       
00282       if(theErr && *theErr < 0)
00283         return -1;
00284       
00285       TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
00286       TValueHolder<TString, char> aMeshName(anInfo.myName);
00287 
00288       return MEDnFam(myFile->Id(),
00289                      &aMeshName,
00290                      0,
00291                      MED_FAMILLE);
00292     }
00293     
00294     
00295     TInt
00296     TVWrapper
00297     ::GetNbFamAttr(TInt theFamId, 
00298                    const TMeshInfo& theInfo,
00299                    TErr* theErr)
00300     {
00301       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00302       
00303       if(theErr && *theErr < 0)
00304         return -1;
00305       
00306       TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
00307       TValueHolder<TString, char> aMeshName(anInfo.myName);
00308 
00309       return MEDnFam(myFile->Id(),
00310                      &aMeshName,
00311                      theFamId,
00312                      MED_ATTR);
00313     }
00314     
00315     
00316     TInt
00317     TVWrapper
00318     ::GetNbFamGroup(TInt theFamId, 
00319                     const TMeshInfo& theInfo,
00320                     TErr* theErr)
00321     {
00322       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00323       
00324       if(theErr && *theErr < 0)
00325         return -1;
00326       
00327       TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
00328       TValueHolder<TString, char> aMeshName(anInfo.myName);
00329 
00330       return MEDnFam(myFile->Id(),
00331                      &aMeshName,
00332                      theFamId,
00333                      MED_GROUPE);
00334     }
00335     
00336     
00337     void
00338     TVWrapper
00339     ::GetFamilyInfo(TInt theFamId, 
00340                     TFamilyInfo& theInfo,
00341                     TErr* theErr)
00342     {
00343       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00344       
00345       if(theErr && *theErr < 0)
00346         return;
00347       
00348       TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
00349       
00350       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
00351       TValueHolder<TString, char> aFamilyName(theInfo.myName);
00352       TValueHolder<TInt, med_int> aFamilyId(theInfo.myId);
00353       TValueHolder<TFamAttr, med_int> anAttrId(theInfo.myAttrId);
00354       TValueHolder<TFamAttr, med_int> anAttrVal(theInfo.myAttrVal);
00355       TValueHolder<TInt, med_int> aNbAttr(theInfo.myNbAttr);
00356       TValueHolder<TString, char> anAttrDesc(theInfo.myAttrDesc);
00357       TValueHolder<TInt, med_int> aNbGroup(theInfo.myNbGroup);
00358       TValueHolder<TString, char> aGroupNames(theInfo.myGroupNames);
00359 
00360       TErr aRet = MEDfamInfo(myFile->Id(),
00361                              &aMeshName,
00362                              theFamId,
00363                              &aFamilyName,
00364                              &aFamilyId,
00365                              &anAttrId,
00366                              &anAttrVal,
00367                              &anAttrDesc,
00368                              &aNbAttr,
00369                              &aGroupNames,
00370                              &aNbGroup);
00371       
00372       if(theErr) 
00373         *theErr = aRet;
00374       else if(aRet < 0)
00375         EXCEPTION(std::runtime_error,"GetFamilyInfo - MEDfamInfo - "<<
00376                   "&aMeshInfo.myName[0] = '"<<&aMeshName<<"'; "<<
00377                   "theFamId = "<<theFamId<<"; "<<
00378                   "&theInfo.myName[0] = '"<<&aFamilyName<<"'; "<<
00379                   "theInfo.myId = "<<theInfo.myId);
00380     }
00381     
00382     
00383     void 
00384     TVWrapper
00385     ::SetFamilyInfo(const TFamilyInfo& theInfo,
00386                     EModeAcces theMode,
00387                     TErr* theErr)
00388     {
00389       TFileWrapper aFileWrapper(myFile,theMode,theErr);
00390       
00391       if(theErr && *theErr < 0)
00392         return;
00393       
00394       TFamilyInfo& anInfo = const_cast<TFamilyInfo&>(theInfo);
00395       TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
00396       
00397       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
00398       TValueHolder<TString, char> aFamilyName(anInfo.myName);
00399       TValueHolder<TInt, med_int> aFamilyId(anInfo.myId);
00400       TValueHolder<TFamAttr, med_int> anAttrId(anInfo.myAttrId);
00401       TValueHolder<TFamAttr, med_int> anAttrVal(anInfo.myAttrVal);
00402       TValueHolder<TInt, med_int> aNbAttr(anInfo.myNbAttr);
00403       TValueHolder<TString, char> anAttrDesc(anInfo.myAttrDesc);
00404       TValueHolder<TInt, med_int> aNbGroup(anInfo.myNbGroup);
00405       TValueHolder<TString, char> aGroupNames(anInfo.myGroupNames);
00406 
00407       TErr aRet = MEDfamCr(myFile->Id(),
00408                            &aMeshName,
00409                            &aFamilyName,
00410                            aFamilyId,
00411                            &anAttrId,
00412                            &anAttrVal,
00413                            &anAttrDesc,
00414                            aNbAttr,
00415                            &aGroupNames,
00416                            aNbGroup);
00417       
00418       INITMSG(MYDEBUG && aRet,"TVWrapper::SetFamilyInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
00419       
00420       if(theErr) 
00421         *theErr = aRet;
00422       else if(aRet < 0)
00423         EXCEPTION(std::runtime_error,"SetFamilyInfo - MEDfamCr(...)");
00424     }
00425     
00426     
00427     void 
00428     TVWrapper
00429     ::SetFamilyInfo(const TFamilyInfo& theInfo,
00430                     TErr* theErr)
00431     {
00432       TErr aRet;
00433       SetFamilyInfo(theInfo,eECRI,&aRet);
00434       
00435       if(aRet < 0)
00436         SetFamilyInfo(theInfo,eREMP,&aRet);
00437 
00438       if(theErr) 
00439         *theErr = aRet;
00440     }
00441     
00442     
00443     TInt
00444     TVWrapper
00445     ::GetNbNodes(const TMeshInfo& theMeshInfo,
00446                  TErr* theErr)
00447     {
00448       MSG(MYDEBUG,"TVWrapper::GetNbNodes");
00449       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00450       
00451       if(theErr && *theErr < 0)
00452         return -1;
00453       
00454       TMeshInfo& aMeshInfo = const_cast<TMeshInfo&>(theMeshInfo);
00455       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
00456       
00457       TInt aRet = MEDnEntMaa(myFile->Id(),
00458                              &aMeshName,
00459                              MED_COOR,
00460                              MED_NOEUD,
00461                              med_geometrie_element(0),
00462                              med_connectivite(0));
00463       return aRet;
00464     }
00465     
00466     
00467     void 
00468     TVWrapper
00469     ::GetNodeInfo(TNodeInfo& theInfo,
00470                   TErr* theErr)
00471     {
00472       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00473       
00474       if(theErr && *theErr < 0)
00475         return;
00476       
00477       TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
00478 
00479       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
00480       TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
00481       TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord);
00482       TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theInfo.myModeSwitch);
00483       TValueHolder<ERepere, med_repere> aSystem(theInfo.mySystem);
00484       TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames);
00485       TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits);
00486       TValueHolder<TString, char> anElemNames(theInfo.myElemNames);
00487       TValueHolder<EBooleen, med_booleen> anIsElemNames(theInfo.myIsElemNames);
00488       TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum);
00489       TValueHolder<EBooleen, med_booleen> anIsElemNum(theInfo.myIsElemNum);
00490       TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
00491       TValueHolder<TInt, med_int> aNbElem(theInfo.myNbElem);
00492 
00493       TErr aRet = MEDnoeudsLire(myFile->Id(),
00494                                 &aMeshName,
00495                                 aDim,
00496                                 &aCoord,
00497                                 aModeSwitch,
00498                                 &aSystem,
00499                                 &aCoordNames,
00500                                 &aCoordUnits,
00501                                 &anElemNames,
00502                                 &anIsElemNames,
00503                                 &anElemNum,
00504                                 &anIsElemNum,
00505                                 &aFamNum,
00506                                 aNbElem);
00507 
00508       if(theErr) 
00509         *theErr = aRet;
00510       else if(aRet < 0)
00511         EXCEPTION(std::runtime_error,"GetNodeInfo - MEDnoeudsLire(...)");
00512     }
00513     
00514     
00515     void 
00516     TVWrapper
00517     ::SetNodeInfo(const MED::TNodeInfo& theInfo,
00518                   EModeAcces theMode,
00519                   TErr* theErr)
00520     {
00521       TFileWrapper aFileWrapper(myFile,theMode,theErr);
00522       
00523       if(theErr && *theErr < 0)
00524         return;
00525       
00526       MED::TNodeInfo& anInfo = const_cast<MED::TNodeInfo&>(theInfo);
00527       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
00528 
00529       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
00530       TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
00531       TValueHolder<TNodeCoord, med_float> aCoord(anInfo.myCoord);
00532       TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(anInfo.myModeSwitch);
00533       TValueHolder<ERepere, med_repere> aSystem(anInfo.mySystem);
00534       TValueHolder<TString, char> aCoordNames(anInfo.myCoordNames);
00535       TValueHolder<TString, char> aCoordUnits(anInfo.myCoordUnits);
00536       TValueHolder<TString, char> anElemNames(anInfo.myElemNames);
00537       TValueHolder<EBooleen, med_booleen> anIsElemNames(anInfo.myIsElemNames);
00538       TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
00539       TValueHolder<EBooleen, med_booleen> anIsElemNum(anInfo.myIsElemNum);
00540       TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum);
00541       TValueHolder<TInt, med_int> aNbElem(anInfo.myNbElem);
00542 
00543       TErr aRet = MEDnoeudsEcr(myFile->Id(),
00544                                &aMeshName,
00545                                aDim,
00546                                &aCoord,
00547                                aModeSwitch,
00548                                aSystem,
00549                                &aCoordNames,
00550                                &aCoordUnits,
00551                                &anElemNames,
00552                                anIsElemNames,
00553                                &anElemNum,
00554                                anIsElemNum,
00555                                &aFamNum,
00556                                aNbElem,
00557                                MED_REMP);
00558       if(theErr) 
00559         *theErr = aRet;
00560       else if(aRet < 0)
00561         EXCEPTION(std::runtime_error,"SetNodeInfo - MEDnoeudsEcr(...)");
00562     }
00563     
00564     
00565     void 
00566     TVWrapper
00567     ::SetNodeInfo(const MED::TNodeInfo& theInfo,
00568                   TErr* theErr)
00569     {
00570       TErr aRet;
00571       SetNodeInfo(theInfo,eECRI,&aRet);
00572       
00573       if(aRet < 0)
00574         SetNodeInfo(theInfo,eREMP,&aRet);
00575 
00576       if(theErr) 
00577         *theErr = aRet;
00578     }
00579     
00580     
00581     TEntityInfo
00582     TVWrapper
00583     ::GetEntityInfo(const TMeshInfo& theMeshInfo,
00584                     EConnectivite theConnMode,
00585                     TErr* theErr)
00586     {
00587       TEntityInfo anInfo;
00588       
00589       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00590       
00591       if(theErr && *theErr < 0)
00592         return anInfo;
00593       
00594       TInt aNbElem = GetNbNodes(theMeshInfo);
00595       if(aNbElem > 0){
00596         anInfo[eNOEUD][ePOINT1] = aNbElem;
00597         const TEntity2GeomSet& anEntity2GeomSet = GetEntity2GeomSet();
00598         TEntity2GeomSet::const_iterator anIter = anEntity2GeomSet.begin();
00599         TEntity2GeomSet::const_iterator anIterEnd = anEntity2GeomSet.end();
00600         for(; anIter != anIterEnd; anIter++){
00601           const EEntiteMaillage& anEntity = anIter->first;
00602           const TGeomSet& aGeomSet = anIter->second;
00603           TGeomSet::const_iterator anIter2 = aGeomSet.begin();
00604           TGeomSet::const_iterator anIterEnd2 = aGeomSet.end();
00605           for(; anIter2 != anIterEnd2; anIter2++){
00606             const EGeometrieElement& aGeom = *anIter2;
00607             aNbElem = GetNbCells(theMeshInfo,anEntity,aGeom,theConnMode,theErr);
00608             if(aNbElem > 0)
00609               anInfo[anEntity][aGeom] = aNbElem;
00610           }
00611         }
00612       }
00613       return anInfo;
00614     }
00615     
00616     
00617     TInt
00618     TVWrapper
00619     ::GetNbCells(const MED::TMeshInfo& theMeshInfo, 
00620                  EEntiteMaillage theEntity, 
00621                  EGeometrieElement theGeom, 
00622                  EConnectivite theConnMode,
00623                  TErr* theErr)
00624     {
00625       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00626       
00627       if(theErr && *theErr < 0)
00628         return -1;
00629       
00630       MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
00631       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
00632       
00633       return MEDnEntMaa(myFile->Id(),
00634                         &aMeshName,
00635                         MED_CONN,
00636                         med_entite_maillage(theEntity),
00637                         med_geometrie_element(theGeom),
00638                         med_connectivite(theConnMode)); 
00639     }
00640     
00641     
00642     void 
00643     TVWrapper
00644     ::GetCellInfo(MED::TCellInfo& theInfo,
00645                   TErr* theErr)
00646     {
00647       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00648 
00649       if(theErr && *theErr < 0)
00650         return;
00651       
00652       MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
00653       TInt aNbElem = theInfo.myElemNum->size();
00654 
00655       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
00656       TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
00657       TValueHolder<TElemNum, med_int> aConn(theInfo.myConn);
00658       TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theInfo.myModeSwitch);
00659       TValueHolder<TString, char> anElemNames(theInfo.myElemNames);
00660       TValueHolder<EBooleen, med_booleen> anIsElemNames(theInfo.myIsElemNames);
00661       TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum);
00662       TValueHolder<EBooleen, med_booleen> anIsElemNum(theInfo.myIsElemNum);
00663       TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
00664       TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theInfo.myEntity);
00665       TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(theInfo.myGeom);
00666       TValueHolder<EConnectivite, med_connectivite> aConnMode(theInfo.myConnMode);
00667 
00668       TErr aRet;
00669       aRet = MEDelementsLire(myFile->Id(),
00670                              &aMeshName,
00671                              aDim,
00672                              &aConn,
00673                              aModeSwitch,
00674                              &anElemNames,
00675                              &anIsElemNames,
00676                              &anElemNum,
00677                              &anIsElemNum,
00678                              &aFamNum,
00679                              aNbElem,
00680                              anEntity,
00681                              aGeom,
00682                              aConnMode);
00683 
00684       if(theErr) 
00685         *theErr = aRet;
00686       else if(aRet < 0)
00687         EXCEPTION(std::runtime_error,"GetCellInfo - MEDelementsLire(...)");
00688     }
00689     
00690     
00691     void 
00692     TVWrapper
00693     ::SetCellInfo(const MED::TCellInfo& theInfo,
00694                   EModeAcces theMode,
00695                   TErr* theErr)
00696     {
00697       TFileWrapper aFileWrapper(myFile,theMode,theErr);
00698       
00699       if(theErr && *theErr < 0)
00700         return;
00701 
00702       MED::TCellInfo& anInfo = const_cast<MED::TCellInfo&>(theInfo);
00703       MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
00704 
00705       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
00706       TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
00707       TValueHolder<TElemNum, med_int> aConn(anInfo.myConn);
00708       TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(anInfo.myModeSwitch);
00709       TValueHolder<TString, char> anElemNames(anInfo.myElemNames);
00710       TValueHolder<EBooleen, med_booleen> anIsElemNames(anInfo.myIsElemNames);
00711       TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
00712       TValueHolder<EBooleen, med_booleen> anIsElemNum(anInfo.myIsElemNum);
00713       TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum);
00714       TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(anInfo.myEntity);
00715       TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(anInfo.myGeom);
00716       TValueHolder<EConnectivite, med_connectivite> aConnMode(anInfo.myConnMode);
00717 
00718       TErr aRet;
00719       aRet = MEDelementsEcr(myFile->Id(),
00720                             &aMeshName,
00721                             aDim,
00722                             &aConn,
00723                             aModeSwitch,
00724                             &anElemNames,
00725                             anIsElemNames,
00726                             &anElemNum,
00727                             anIsElemNum,
00728                             &aFamNum,
00729                             anInfo.myNbElem,
00730                             anEntity,
00731                             aGeom,
00732                             aConnMode,
00733                             MED_REMP);
00734       
00735       if(theErr) 
00736         *theErr = aRet;
00737       else if(aRet < 0)
00738         EXCEPTION(std::runtime_error,"GetCellInfo - MEDelementsLire(...)");
00739     }
00740     
00741 
00742     void
00743     TVWrapper
00744     ::SetCellInfo(const MED::TCellInfo& theInfo,
00745                   TErr* theErr)
00746     {
00747       TErr aRet;
00748       SetCellInfo(theInfo,eECRI,&aRet);
00749       
00750       if(aRet < 0)
00751         SetCellInfo(theInfo,eREMP,&aRet);
00752 
00753       if(theErr) 
00754         *theErr = aRet;
00755     }
00756     
00757 
00758     TInt
00759     TVWrapper
00760     ::GetNbFields(TErr* theErr)
00761     {
00762       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00763       
00764       if(theErr && *theErr < 0)
00765         return -1;
00766       
00767       return MEDnChamp(myFile->Id(),0);
00768     }
00769     
00770     
00771     TInt
00772     TVWrapper
00773     ::GetNbComp(TInt theFieldId,
00774                 TErr* theErr)
00775     {
00776       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00777       
00778       if(theErr && *theErr < 0)
00779         return -1;
00780       
00781       return MEDnChamp(myFile->Id(),theFieldId);
00782     }
00783     
00784     
00785     void 
00786     TVWrapper
00787     ::GetFieldInfo(TInt theFieldId, 
00788                    MED::TFieldInfo& theInfo,
00789                    TErr* theErr)
00790     {
00791       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00792       
00793       if(theErr && *theErr < 0)
00794         return;
00795       
00796       TString aFieldName(256); // Protect from memory problems with too long names
00797       TValueHolder<ETypeChamp, med_type_champ> aType(theInfo.myType);
00798       TValueHolder<TString, char> aCompNames(theInfo.myCompNames);
00799       TValueHolder<TString, char> anUnitNames(theInfo.myUnitNames);
00800 
00801       TErr aRet;
00802       aRet = MEDchampInfo(myFile->Id(),
00803                           theFieldId,
00804                           &aFieldName[0],
00805                           &aType,
00806                           &aCompNames,
00807                           &anUnitNames,
00808                           theInfo.myNbComp);
00809 
00810       theInfo.SetName(aFieldName);
00811 
00812       if(theErr) 
00813         *theErr = aRet;
00814       else if(aRet < 0)
00815         EXCEPTION(std::runtime_error,"GetFieldInfo - MEDchampInfo(...)");
00816     }
00817     
00818     
00819     void
00820     TVWrapper
00821     ::SetFieldInfo(const MED::TFieldInfo& theInfo,
00822                    EModeAcces theMode,
00823                    TErr* theErr)
00824     {
00825       TFileWrapper aFileWrapper(myFile,theMode,theErr);
00826       
00827       if(theErr && *theErr < 0)
00828         return;
00829       
00830       MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
00831       
00832       TValueHolder<TString, char> aFieldName(anInfo.myName);
00833       TValueHolder<ETypeChamp, med_type_champ> aType(anInfo.myType);
00834       TValueHolder<TString, char> aCompNames(anInfo.myCompNames);
00835       TValueHolder<TString, char> anUnitNames(anInfo.myUnitNames);
00836 
00837       TErr aRet;
00838       aRet = MEDchampCr(myFile->Id(),
00839                         &aFieldName,
00840                         aType,
00841                         &aCompNames,
00842                         &anUnitNames,
00843                         anInfo.myNbComp);
00844 
00845       if(theErr) 
00846         *theErr = aRet;
00847       else if(aRet < 0)
00848         EXCEPTION(std::runtime_error,"SetFieldInfo - MEDchampCr(...)");
00849     }
00850     
00851     
00852     void
00853     TVWrapper
00854     ::SetFieldInfo(const MED::TFieldInfo& theInfo,
00855                    TErr* theErr)
00856     {
00857       try{
00858 
00859         TErr aRet;
00860         SetFieldInfo(theInfo,eECRI,&aRet);
00861       
00862         if(aRet < 0)
00863           SetFieldInfo(theInfo,eREMP,&aRet);
00864 
00865         if(theErr) 
00866           *theErr = aRet;
00867 
00868       }catch(const std::exception& theExc){
00869         EXCEPTION(std::runtime_error,"SetFieldInfo(...)"<<std::endl<<
00870                   theExc.what());
00871       }catch(...){
00872         throw;
00873       }
00874     }
00875     
00876     //-----------------------------------------------------------------
00877     TInt
00878     TVWrapper
00879     ::GetNbProfiles(TErr* theErr)
00880     {
00881       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00882       
00883       if(theErr && *theErr < 0)
00884         return -1;
00885       
00886       return MEDnProfil(myFile->Id());
00887     }
00888 
00889 
00890     TProfileInfo::TInfo
00891     TVWrapper
00892     ::GetProfilePreInfo(TInt theId, 
00893                         TErr* theErr)
00894     {
00895       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00896 
00897       if(theErr && *theErr < 0)
00898         return TProfileInfo::TInfo("",-1);
00899       
00900       med_int aSize = -1;
00901       TVector<char> aName(GetNOMLength<eV2_1>()+1);
00902 
00903       TErr aRet;
00904       aRet = MEDprofilInfo(myFile->Id(),
00905                            theId,
00906                            &aName[0],
00907                            &aSize);
00908       if(theErr) 
00909         *theErr = aRet;
00910       else if(aRet < 0)
00911         EXCEPTION(std::runtime_error,"GetProfilePreInfo - MEDprofilInfo(...)");
00912       
00913       return TProfileInfo::TInfo(&aName[0],aSize);
00914     }
00915 
00916 
00917     void
00918     TVWrapper
00919     ::GetProfileInfo(TInt theId, 
00920                      TProfileInfo& theInfo,
00921                      TErr* theErr)
00922     {
00923       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00924       
00925       if(theErr && *theErr < 0)
00926         return;
00927       
00928       TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum);
00929       TValueHolder<TString, char> aProfileName(theInfo.myName);
00930 
00931       TErr aRet;
00932       aRet = MEDprofilLire(myFile->Id(),
00933                            &anElemNum,
00934                            &aProfileName);
00935       if(theErr) 
00936         *theErr = aRet;
00937       else if(aRet < 0)
00938         EXCEPTION(std::runtime_error,"GetProfileInfo - MEDprofilLire(...)");
00939     }
00940 
00941     void
00942     TVWrapper
00943     ::SetProfileInfo(const TProfileInfo& theInfo,
00944                      EModeAcces          theMode,
00945                      TErr*               theErr)
00946     {
00947       TFileWrapper aFileWrapper(myFile,theMode,theErr);
00948       
00949       if(theErr && *theErr < 0)
00950         return;
00951       
00952       TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo);
00953       TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
00954       TValueHolder<TString, char>     aProfileName(anInfo.myName);
00955 
00956       TErr aRet;
00957       aRet = MEDprofilEcr(myFile->Id(),      // descripteur du fichier.
00958                           &anElemNum,        // tableau de valeurs du profil.
00959                           theInfo.GetSize(), // taille du profil.
00960                           &aProfileName);    // nom profil.
00961       if(theErr)
00962         *theErr = aRet;
00963       else if(aRet < 0)
00964         EXCEPTION(std::runtime_error,"SetProfileInfo - MEDprofilEcr(...)");
00965     }
00966 
00967     void
00968     TVWrapper
00969     ::SetProfileInfo(const TProfileInfo& theInfo,
00970                      TErr* theErr)
00971     {
00972       TErr aRet;
00973       SetProfileInfo(theInfo,eECRI,&aRet);
00974       
00975       if(aRet < 0)
00976         SetProfileInfo(theInfo,eREMP,&aRet);
00977 
00978       if(theErr) 
00979         *theErr = aRet;
00980     }
00981 
00982     //-----------------------------------------------------------------
00983     TInt
00984     TVWrapper
00985     ::GetNbTimeStamps(const MED::TFieldInfo& theInfo, 
00986                       const MED::TEntityInfo& theEntityInfo,
00987                       EEntiteMaillage& theEntity,
00988                       TGeom2Size& theGeom2Size,
00989                       TErr* theErr)
00990     {
00991       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
00992       
00993       if(theErr){
00994         if(theEntityInfo.empty())
00995           *theErr = -1;
00996         if(*theErr < 0)
00997           return -1;
00998       }else if(theEntityInfo.empty()) 
00999         EXCEPTION(std::runtime_error,"GetNbTimeStamps - There is no any Entity on the Mesh");
01000 
01001       bool anIsPerformAdditionalCheck = GetNbMeshes() > 1;
01002 #ifdef _DEBUG_
01003       static bool anIsCheckOnlyFirstTimeStamp = false;
01004 #else
01005       static bool anIsCheckOnlyFirstTimeStamp = true;
01006 #endif
01007 
01008       theGeom2Size.clear();
01009       TInt aNbTimeStamps = 0;
01010       TIdt anId = myFile->Id();
01011 
01012       MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
01013       TValueHolder<TString, char> aFieldName(anInfo.myName);
01014       MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo;
01015 
01016       TEntityInfo::const_iterator anIter = theEntityInfo.begin();
01017       for(; anIter != theEntityInfo.end(); anIter++){
01018         med_entite_maillage anEntity = med_entite_maillage(anIter->first);
01019         const TGeom2Size& aGeom2Size = anIter->second;
01020         TGeom2Size::const_iterator anGeomIter = aGeom2Size.begin();
01021         for(; anGeomIter != aGeom2Size.end(); anGeomIter++){
01022           med_geometrie_element aGeom = med_geometrie_element(anGeomIter->first);
01023           TInt aNbStamps = MEDnPasdetemps(anId,
01024                                           &aFieldName,
01025                                           anEntity,
01026                                           aGeom);
01027           bool anIsSatisfied = aNbStamps > 0;
01028           if(anIsSatisfied){
01029             INITMSG(MYDEBUG,
01030                     "GetNbTimeStamps aNbTimeStamps = "<<aNbStamps<<
01031                     "; aGeom = "<<aGeom<<"; anEntity = "<<anEntity<<"\n");
01032             if(anIsPerformAdditionalCheck){
01033               TInt iTimeStampEnd = anIsCheckOnlyFirstTimeStamp? 1: aNbStamps;
01034               for(TInt iTimeStamp = 1; iTimeStamp <= iTimeStampEnd; iTimeStamp++){
01035                 TVector<char> aMeshName(GetNOMLength<eV2_1>()+1);
01036                 TVector<char> aDtUnit(GetPNOMLength<eV2_1>()+1);
01037                 med_int aNbGauss;
01038                 med_int aNumDt;
01039                 med_int aNumOrd;
01040                 med_float aDt;
01041                 TErr aRet = MEDpasdetempsInfo(anId,
01042                                               &aFieldName,
01043                                               anEntity,
01044                                               aGeom,
01045                                               iTimeStamp, 
01046                                               &aMeshName[0],
01047                                               &aNbGauss,
01048                                               &aNumDt,  
01049                                               &aDtUnit[0],
01050                                               &aDt, 
01051                                               &aNumOrd);
01052                 
01053                 anIsSatisfied = (aRet == 0 && (!strcmp(&aMeshName[0],&aMeshInfo.myName[0])));
01054                 if(!anIsSatisfied){
01055                   INITMSG(MYDEBUG,
01056                           "GetNbTimeStamps aMeshName = '"<<&aMeshName[0]<<"' != "<<
01057                           "; aMeshInfo.myName = '"<<&aMeshInfo.myName[0]<<"'\n");
01058                   break;
01059                 }
01060               }
01061             }
01062           }
01063           if(anIsSatisfied){
01064             theGeom2Size[EGeometrieElement(aGeom)] = anGeomIter->second;
01065             theEntity = EEntiteMaillage(anEntity);
01066             aNbTimeStamps = aNbStamps;
01067           }
01068         }
01069         if(!theGeom2Size.empty()) 
01070           break;
01071       }
01072       return aNbTimeStamps;
01073     }
01074     
01075     
01076     void
01077     TVWrapper
01078     ::GetTimeStampInfo(TInt theTimeStampId, 
01079                        MED::TTimeStampInfo& theInfo,
01080                        TErr* theErr)
01081     {
01082       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
01083       
01084       const TGeom2Size& aGeom2Size = theInfo.myGeom2Size;     
01085 
01086       if(theErr){
01087         if(aGeom2Size.empty())
01088           *theErr = -1;
01089         if(*theErr < 0)
01090           return;
01091       }else if(aGeom2Size.empty())
01092         EXCEPTION(std::runtime_error,"GetTimeStampInfo - There is no any cell");
01093       
01094       MED::TFieldInfo& aFieldInfo = *theInfo.myFieldInfo;
01095       MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
01096       
01097       TValueHolder<TString, char> aFieldName(aFieldInfo.myName);
01098       TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theInfo.myEntity);
01099       TValueHolder<TInt, med_int> aNumDt(theInfo.myNumDt);
01100       TValueHolder<TInt, med_int> aNumOrd(theInfo.myNumOrd);
01101       TValueHolder<TString, char> anUnitDt(theInfo.myUnitDt);
01102       TValueHolder<TFloat, med_float> aDt(theInfo.myDt);
01103       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
01104 
01105       TGeom2NbGauss& aGeom2NbGauss = theInfo.myGeom2NbGauss;
01106 
01107       TGeom2Size::const_iterator anIter = aGeom2Size.begin();
01108       for(; anIter != aGeom2Size.end(); anIter++){
01109         const EGeometrieElement& aGeom = anIter->first;
01110         med_int aNbGauss = -1;
01111 
01112         TErr aRet;
01113         aRet = MEDpasdetempsInfo(myFile->Id(),
01114                                  &aFieldName,
01115                                  anEntity,
01116                                  med_geometrie_element(aGeom),
01117                                  theTimeStampId,
01118                                  &aMeshName,
01119                                  &aNbGauss,
01120                                  &aNumDt,
01121                                  &anUnitDt,
01122                                  &aDt,
01123                                  &aNumOrd);
01124         
01125         
01126         static TInt MAX_NB_GAUSS_POINTS = 32;
01127         if(aNbGauss <= 0 || aNbGauss > MAX_NB_GAUSS_POINTS)
01128           aNbGauss = 1;
01129 
01130         aGeom2NbGauss[aGeom] = aNbGauss;
01131         
01132         if(theErr) 
01133           *theErr = aRet;
01134         else if(aRet < 0)
01135           EXCEPTION(std::runtime_error,"GetTimeStampInfo - MEDpasdetempsInfo(...)");
01136       }
01137     }
01138     
01139 
01140     void 
01141     TVWrapper
01142     ::GetTimeStampValue(const PTimeStampValueBase& theTimeStampValue,
01143                         const TMKey2Profile& theMKey2Profile,
01144                         const TKey2Gauss& theKey2Gauss,
01145                         TErr* theErr)
01146     {
01147       TFileWrapper aFileWrapper(myFile,eLECT,theErr);
01148       
01149       if(theErr && *theErr < 0)
01150         return;
01151       
01152       TIdt anId = myFile->Id();
01153       
01154       TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theTimeStampValue->myModeSwitch);
01155       MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile;
01156 
01157       MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo;
01158       TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(aTimeStampInfo->myEntity);
01159       TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt);
01160       TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd);
01161 
01162       MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo;
01163       TValueHolder<TString, char> aFieldName(aFieldInfo->myName);
01164 
01165       MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo;
01166       TValueHolder<TString, char> aMeshName(aMeshInfo->myName);
01167       
01168       MED::TKey2Profile aKey2Profile = boost::get<1>(theMKey2Profile);
01169       TVector<char> aProfileName(GetNOMLength<eV2_1>()+1);
01170 
01171       TGeom2Size& aGeom2Size = aTimeStampInfo->myGeom2Size;
01172       TGeom2Size::iterator anIter = aGeom2Size.begin();
01173       for(; anIter != aGeom2Size.end(); anIter++){
01174         EGeometrieElement aGeom = anIter->first;
01175         TInt aNbElem = anIter->second;
01176 
01177         TInt aNbVal = MEDnVal(anId,
01178                               &aFieldName,
01179                               anEntity,
01180                               med_geometrie_element(aGeom),
01181                               aNumDt,
01182                               aNumOrd);
01183         if(aNbVal <= 0){
01184           if(theErr){
01185             *theErr = -1;
01186             return;
01187           }
01188           EXCEPTION(std::runtime_error,"GetTimeStampValue - MEDnVal(...) - aNbVal == "<<aNbVal<<" <= 0");
01189         }
01190         
01191         TInt aNbGauss = aTimeStampInfo->GetNbGauss(aGeom);
01192         TInt aNbComp = aFieldInfo->myNbComp;
01193         TInt aNbValue = aNbVal / aNbGauss;
01194         theTimeStampValue->AllocateValue(aGeom,
01195                                          aNbValue,
01196                                          aNbGauss,
01197                                          aNbComp);
01198         TInt aValueSize = theTimeStampValue->GetValueSize(aGeom);
01199 
01200         INITMSG(MYDEBUG,
01201                 "TVWrapper::GetTimeStampValue - aGeom = "<<aGeom<<
01202                 "; aNbVal = "<<aNbVal<<
01203                 "; aNbValue = "<<aNbValue<<
01204                 "; aNbGauss = "<<aNbGauss<<
01205                 "; aNbComp = "<<aNbComp<<
01206                 std::endl);
01207 
01208         TErr aRet = MEDchampLire(anId,
01209                                  &aMeshName,
01210                                  &aFieldName,
01211                                  theTimeStampValue->GetValuePtr(aGeom),
01212                                  aModeSwitch,
01213                                  MED_ALL,
01214                                  &aProfileName[0],
01215                                  anEntity,
01216                                  med_geometrie_element(aGeom),
01217                                  aNumDt,
01218                                  aNumOrd);
01219         if(aRet < 0){
01220           if(theErr){
01221             *theErr = aRet;
01222             return;
01223           }
01224           EXCEPTION(std::runtime_error,"GetTimeStampValue - MEDchampLire(...)");
01225         }
01226 
01227         MED::PProfileInfo aProfileInfo;
01228         if(strcmp(&aProfileName[0],"") != 0){
01229           MED::TKey2Profile::const_iterator anIter = aKey2Profile.find(&aProfileName[0]);
01230           if(anIter != aKey2Profile.end()){
01231             aProfileInfo = anIter->second;
01232             aGeom2Profile[aGeom] = aProfileInfo;
01233           }
01234         }
01235           
01236         if(aProfileInfo && aProfileInfo->IsPresent()){
01237           TInt aNbSubElem = aProfileInfo->GetSize();
01238           TInt aProfileSize = aNbSubElem*aNbComp*aNbGauss;
01239           if(aProfileSize > aValueSize){
01240             if(theErr){
01241               *theErr = -1;
01242               return;
01243             }
01244             EXCEPTION(std::runtime_error,
01245                       "GetTimeStampValue - aProfileSize("<<aProfileSize<<
01246                       ") != aValueSize("<<aValueSize<<
01247                       "); aNbVal = "<<aNbVal<<
01248                       "; anEntity = "<<anEntity<<
01249                       "; aGeom = "<<aGeom<<
01250                       "; aNbElem = "<<aNbElem<<
01251                       "; aNbSubElem = "<<aNbSubElem<<
01252                       "; aNbComp = "<<aNbComp<<
01253                       "; aNbGauss = "<<aNbGauss<<
01254                       "");
01255           }else{
01256             if(aNbElem != aNbValue){
01257               if(theErr){
01258                 *theErr = -1;
01259                 return;
01260               }
01261               EXCEPTION(std::runtime_error,
01262                         "GetTimeStampValue - aNbElem("<<aNbElem<<
01263                         ") != aNbValue("<<aNbValue<<
01264                         "); aNbVal = "<<aNbVal<<
01265                         "; anEntity = "<<anEntity<<
01266                         "; aGeom = "<<aGeom<<
01267                         "; aNbElem = "<<aNbElem<<
01268                         "; aNbComp = "<<aNbComp<<
01269                         "; aNbGauss = "<<aNbGauss<<
01270                         "");
01271             }
01272           }
01273         }
01274       }
01275     }
01276     
01277     
01278     void
01279     TVWrapper
01280     ::SetTimeStampValue(const MED::PTimeStampValueBase& theTimeStampValue,
01281                         EModeAcces theMode,
01282                         TErr* theErr)
01283     {
01284       TFileWrapper aFileWrapper(myFile,theMode,theErr);
01285       
01286       if(theErr && *theErr < 0)
01287         return;
01288       
01289       TErr aRet;
01290       TIdt anId = myFile->Id();
01291       
01292       TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theTimeStampValue->myModeSwitch);
01293       MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile;
01294 
01295       MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo;
01296       TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(aTimeStampInfo->myEntity);
01297       TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt);
01298       TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd);
01299       TValueHolder<TString, char> anUnitDt(aTimeStampInfo->myUnitDt);
01300       TValueHolder<TFloat, med_float> aDt(aTimeStampInfo->myDt);
01301 
01302       MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo;
01303       TValueHolder<TString, char> aFieldName(aFieldInfo->myName);
01304 
01305       MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo;
01306       TValueHolder<TString, char> aMeshName(aMeshInfo->myName);
01307       
01308       const TGeomSet& aGeomSet = theTimeStampValue->myGeomSet;
01309       TGeomSet::const_iterator anIter = aGeomSet.begin();
01310       for(; anIter != aGeomSet.end(); anIter++){
01311         EGeometrieElement aGeom = *anIter;
01312 
01313         TVector<char> aProfileName(GetNOMLength<eV2_1>()+1);
01314         MED::TGeom2Profile::iterator aProfileIter = aGeom2Profile.find(aGeom);
01315         if(aProfileIter != aGeom2Profile.end()){
01316           MED::TProfileInfo& aProfileInfo = aProfileIter->second;
01317           aProfileName = aProfileInfo.myName;
01318         }
01319 
01320         med_int aNbGauss = aTimeStampInfo->GetNbGauss(aGeom);
01321         med_int aNbVal = theTimeStampValue->GetNbVal(aGeom);
01322         
01323         aRet = MEDchampEcr(anId,
01324                            &aMeshName,
01325                            &aFieldName,
01326                            theTimeStampValue->GetValuePtr(aGeom),
01327                            aModeSwitch,
01328                            aNbVal,
01329                            aNbGauss,
01330                            MED_ALL,
01331                            &aProfileName[0],
01332                            MED_ECRI, 
01333                            anEntity,
01334                            med_geometrie_element(aGeom),
01335                            aNumDt,
01336                            &anUnitDt,
01337                            aDt,
01338                            aNumOrd);
01339         if(aRet < 0){
01340           if(theErr){
01341             *theErr = aRet;
01342             break;
01343           }
01344           EXCEPTION(std::runtime_error,"SetTimeStampValue - MEDchampEcr(...)");
01345         }
01346         
01347       }
01348       
01349       INITMSG(MYDEBUG,"TVWrapper::SetTimeStampValue - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
01350     }
01351 
01352     
01353     void
01354     TVWrapper
01355     ::SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue,
01356                         TErr* theErr)
01357     {
01358       TErr aRet;
01359       SetTimeStampValue(theTimeStampValue,eECRI,&aRet);
01360       
01361       if(aRet < 0)
01362         SetTimeStampValue(theTimeStampValue,eREMP,&aRet);
01363 
01364       if(theErr) 
01365         *theErr = aRet;
01366     }
01367     
01368   }
01369 }