Back to index

salome-med  6.5.0
MED_Test.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/Factory/MED_Test.cxx,v 1.6.2.2.6.2.10.1 2012-04-13 08:48:44 vsr Exp $
00027 //
00028 #include "MED_Utilities.hxx"
00029 #include "MED_Algorithm.hxx"
00030 #include "MED_GaussUtils.hxx"
00031 #include "MED_Factory.hxx"
00032 
00033 #ifdef _DEBUG_
00034 static int MYDEBUG = 1;
00035 #else
00036 // static int MYDEBUG = 0;
00037 #endif
00038 
00039 static int MYWRITEDEBUG = 1;
00040 
00041 using namespace MED;
00042 
00043 #undef _DEBUG_
00044 
00045 void CheckMed(const std::string& theFileName)
00046 {
00047   MSG(MYDEBUG,"CheckMed - theFileName = '"<<theFileName<<"'");
00048   {
00049     //TErr anErr;
00050     PWrapper aMed = CrWrapper(theFileName);
00051 
00052     TKey2Gauss aKey2Gauss = GetKey2Gauss(aMed);
00053     TMKey2Profile aMKey2Profile = GetMKey2Profile(aMed);
00054     INITMSG(MYDEBUG,"aMed->GetNbProfiles() = "<<aMed->GetNbProfiles()<<std::endl);
00055 
00056     TInt aNbMeshes = aMed->GetNbMeshes();
00057     BEGMSG(MYDEBUG,"GetNbMeshes() = "<<aNbMeshes<<std::endl);
00058     for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
00059       
00060       PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
00061       INITMSG(MYDEBUG,"aMeshInfo->GetName() = '"<<aMeshInfo->GetName()<<"'"<<std::endl);
00062 
00063       TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
00064       
00065       TEntity2TGeom2ElemInfo anEntity2TGeom2ElemInfo = 
00066         GetEntity2TGeom2ElemInfo(aMed,aMeshInfo,aEntityInfo);
00067 
00068       TFieldInfo2TimeStampInfoSet aFieldInfo2TimeStampInfoSet = 
00069         GetFieldInfo2TimeStampInfoSet(aMed,aMeshInfo,aEntityInfo);
00070       
00071       TEntite2TFieldInfo2TimeStampInfoSet anEntite2TFieldInfo2TimeStampInfoSet = 
00072         GetEntite2TFieldInfo2TimeStampInfoSet(aFieldInfo2TimeStampInfoSet);
00073 
00074       TEntite2TFieldInfo2TimeStampInfoSet::const_iterator anEntite2TFieldInfo2TimeStampInfoSetIter = 
00075         anEntite2TFieldInfo2TimeStampInfoSet.begin();
00076       for(; anEntite2TFieldInfo2TimeStampInfoSetIter != anEntite2TFieldInfo2TimeStampInfoSet.end(); anEntite2TFieldInfo2TimeStampInfoSetIter++){
00077         const TFieldInfo2TimeStampInfoSet& aFieldInfo2TimeStampInfoSet = anEntite2TFieldInfo2TimeStampInfoSetIter->second;
00078         TFieldInfo2TimeStampInfoSet::const_iterator aFieldInfo2TimeStampInfoSetIter = aFieldInfo2TimeStampInfoSet.begin();
00079         for(; aFieldInfo2TimeStampInfoSetIter != aFieldInfo2TimeStampInfoSet.end(); aFieldInfo2TimeStampInfoSetIter++){
00080           PFieldInfo aFieldInfo = aFieldInfo2TimeStampInfoSetIter->first;
00081           INITMSG(MYDEBUG,
00082                   "GetPFieldInfo "<<
00083                   "- aName = '"<<aFieldInfo->GetName()<<"'"<<
00084                   "; aType = "<<aFieldInfo->GetType()<<
00085                   "; aNbComp = "<<aFieldInfo->GetNbComp()<<
00086                   std::endl);
00087           const TTimeStampInfoSet& aTimeStampInfoSet = aFieldInfo2TimeStampInfoSetIter->second;
00088           TTimeStampInfoSet::const_iterator aTimeStampInfoSettIter = aTimeStampInfoSet.begin();
00089           for(; aTimeStampInfoSettIter != aTimeStampInfoSet.end(); aTimeStampInfoSettIter++){
00090             PTimeStampInfo aTimeStampInfo = *aTimeStampInfoSettIter;
00091             INITMSG(MYDEBUG,
00092                     "GetPTimeStampInfo "<<
00093                     "- anEntity = "<<aTimeStampInfo->GetEntity()<<
00094                     "; aNumDt = "<<aTimeStampInfo->GetNumDt()<<
00095                     std::endl);
00096             PTimeStampValueBase aTimeStampValue = 
00097               aMed->GetPTimeStampValue(aTimeStampInfo,
00098                                        aMKey2Profile,
00099                                        aKey2Gauss);
00100           }
00101         }
00102       }
00103 
00104       continue;
00105 
00106       TFamilyInfoSet aFamilyInfoSet = GetFamilyInfoSet(aMed,aMeshInfo);
00107       
00108       TEntity2FamilySet aEntity2FamilySet = 
00109         GetEntity2FamilySet(aMed,anEntity2TGeom2ElemInfo,aFamilyInfoSet);
00110       
00111       TGroupInfo aGroupInfo = GetGroupInfo(aFamilyInfoSet);
00112       
00113       PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
00114       TEntity2TGeom2ElemInfo::const_iterator anIter = anEntity2TGeom2ElemInfo.begin();
00115       for(; anIter != anEntity2TGeom2ElemInfo.end(); anIter++){
00116         const EEntiteMaillage& anEntity = anIter->first;
00117         if(anEntity != eNOEUD){
00118           const TGeom2ElemInfo& aGeom2ElemInfo = anIter->second;
00119           TKey2Gauss::const_iterator anIter2 = aKey2Gauss.begin();
00120           for(; anIter2 != aKey2Gauss.end(); anIter2++){
00121             const TGaussInfo::TKey& aKey = anIter2->first;
00122             EGeometrieElement aGeom = boost::get<0>(aKey);
00123             TGeom2ElemInfo::const_iterator anIter3 = aGeom2ElemInfo.find(aGeom);
00124             if(anIter3 != aGeom2ElemInfo.end()){
00125               if(PCellInfo aCellInfo = anIter3->second){
00126                 PGaussInfo aGaussInfo = anIter2->second;
00127                 TGaussCoord aGaussCoord;
00128                 GetGaussCoord3D(aGaussInfo,aCellInfo,aNodeInfo,aGaussCoord);
00129               }
00130             }
00131           }
00132         }
00133       }
00134       
00135     }
00136   }
00137   MSG(MYDEBUG,"OK");
00138 }
00139 
00140 
00141 void CopyMed(const PWrapper& theMed, 
00142              const PWrapper& theMed2, 
00143              int theIncr)
00144 {
00145   TKey2Gauss aKey2Gauss = GetKey2Gauss(theMed);
00146   TMKey2Profile aMKey2Profile = GetMKey2Profile(theMed);
00147 
00148   TInt aNbMeshes = theMed->GetNbMeshes();
00149   MSG(MYDEBUG,"aNbMeshes = "<<aNbMeshes);
00150   std::string aName;
00151   for(TInt iMesh = 0; iMesh < aNbMeshes; iMesh++){
00152     PMeshInfo aMeshInfo = theMed->GetPMeshInfo(iMesh+1);
00153 #ifdef _DEBUG_
00154     TInt aDim = aMeshInfo->myDim;
00155     aName = aMeshInfo->GetName();
00156     INITMSG(MYDEBUG,"GetMeshInfo - aName = '"<<aName<<"'; aDim = "<<aDim<<"\n");
00157 #endif
00158     PMeshInfo aMeshInfo2 = theMed2->CrMeshInfo(aMeshInfo);
00159     if(MYWRITEDEBUG){
00160       aName = aMeshInfo2->GetName();
00161 
00162       aName[0] += theIncr;
00163       aMeshInfo2->SetName(aName);
00164       theMed2->SetMeshInfo(aMeshInfo2);
00165       BEGMSG(MYDEBUG,"aNbMeshes2 = "<<theMed2->GetNbMeshes()<<"\n");
00166     }
00167     
00168     TEntityInfo aEntityInfo = theMed->GetEntityInfo(aMeshInfo);
00169 
00170     //continue;
00171 
00172     TInt aNbFields = theMed->GetNbFields(); 
00173     MSG(MYDEBUG,"GetNbFields() = "<<aNbFields);
00174     for(TInt iField = 0; iField < aNbFields; iField++){
00175       PFieldInfo aFieldInfo = theMed->GetPFieldInfo(aMeshInfo,iField+1);
00176 #ifdef _DEBUG_
00177       TInt aNbComp = aFieldInfo->GetNbComp();
00178       INITMSG(MYDEBUG,"aName = '"<<aFieldInfo->GetName()<<"'; aNbComp = "<<aNbComp<<";\n");
00179 #endif
00180       PFieldInfo aFieldInfo2 = theMed->CrFieldInfo(aMeshInfo2,aFieldInfo);
00181 
00182       if(MYWRITEDEBUG){
00183         aName = aFieldInfo->GetName();
00184         aName[0] += theIncr;
00185         aFieldInfo2->SetName(aName);
00186         theMed2->SetFieldInfo(aFieldInfo2);
00187       }
00188 
00189       EEntiteMaillage anEntity;
00190       TGeom2Size aGeom2Size;
00191       TInt aNbTimeStamps = 
00192         theMed->GetNbTimeStamps(aFieldInfo,aEntityInfo,anEntity,aGeom2Size);
00193       {
00194         INITMSG(MYDEBUG,"GetNbTimeStamps = "<<aNbTimeStamps<<std::endl);
00195         for(TInt iTimeStamp = 0; iTimeStamp < aNbTimeStamps; iTimeStamp++){
00196           PTimeStampInfo aTimeStampInfo = 
00197           theMed->GetPTimeStampInfo(aFieldInfo,anEntity,aGeom2Size,iTimeStamp+1);
00198 #ifdef _DEBUG_
00199           TInt aNumDt = aTimeStampInfo->GetNumDt();
00200           INITMSG(MYDEBUG,"aNumDt = "<<aNumDt<<"\n");
00201 #endif
00202           
00203           PTimeStampInfo aTimeStampInfo2 = 
00204             theMed->CrTimeStampInfo(aFieldInfo2,aTimeStampInfo);
00205           
00206           PTimeStampValueBase aTimeStampValue = 
00207             theMed->GetPTimeStampValue(aTimeStampInfo,
00208                                        aMKey2Profile,
00209                                        aKey2Gauss);
00210           
00211           PTimeStampValueBase aTimeStampValue2 = 
00212             theMed->CrTimeStampValue(aTimeStampInfo2,
00213                                      aTimeStampValue);
00214           
00215           if(MYWRITEDEBUG) theMed2->SetTimeStamp(aTimeStampValue2);
00216         }
00217       }
00218     }
00219 
00220     TInt aNbFam = theMed->GetNbFamilies(aMeshInfo);
00221     MSG(MYDEBUG,"GetNbFamilies() = "<<aNbFam);
00222     for(TInt iFam = 0; iFam < aNbFam; iFam++){
00223       PFamilyInfo aFamilyInfo = theMed->GetPFamilyInfo(aMeshInfo,iFam+1);
00224       TInt aNbGroup = aFamilyInfo->GetNbGroup();
00225 #ifdef _DEBUG_
00226       TInt aNbAttr = aFamilyInfo->GetNbAttr();
00227 #endif
00228       TInt anId = aFamilyInfo->GetId();
00229       if(anId == 0)
00230         continue;
00231 
00232       aName = aFamilyInfo->GetName();
00233 #ifdef _DEBUG_
00234       INITMSG(MYDEBUG,"aName = '"<<aName<<"'; anId = "<<anId<<
00235               "; aNbAttr = "<<aNbAttr<<"; aNbGroup = "<<aNbGroup<<"\n");
00236 #endif
00237       PFamilyInfo aFamilyInfo2 = theMed->CrFamilyInfo(aMeshInfo2,aFamilyInfo);
00238       for(TInt iGroup = 0; iGroup < aNbGroup; iGroup++){
00239         aName = aFamilyInfo->GetGroupName(iGroup);
00240         INITMSG(MYDEBUG,"aGroupName = '"<<aName<<"'\n");
00241         aName[0] += theIncr;
00242         aFamilyInfo2->SetGroupName(iGroup,aName);
00243       }
00244 
00245       if(MYWRITEDEBUG){
00246         aName = aFamilyInfo->GetName();
00247         aName[0] += theIncr;
00248         aFamilyInfo2->SetName(aName);
00249         theMed2->SetFamilyInfo(aFamilyInfo2);
00250         INITMSG(MYDEBUG,"GetNbFamilies = "<<theMed2->GetNbFamilies(aMeshInfo2)<<std::endl);
00251       }
00252     }
00253 
00254     MSG(MYDEBUG,"GetEntityInfo - aNbEntities = "<<aEntityInfo.size());
00255     TEntityInfo::iterator anEntityInfoIter = aEntityInfo.begin();
00256     for(; anEntityInfoIter != aEntityInfo.end(); anEntityInfoIter++){
00257       const EEntiteMaillage& anEntity = anEntityInfoIter->first;
00258       INITMSG(MYDEBUG,"anEntity = "<<anEntity<<"\n");
00259       if(anEntity == eNOEUD){
00260         PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
00261         PNodeInfo aNodeInfo2 = theMed->CrNodeInfo(aMeshInfo2,aNodeInfo);
00262         if(MYWRITEDEBUG) theMed2->SetNodeInfo(aNodeInfo2);
00263         continue;
00264       }
00265       TGeom2Size& aGeom2Size = anEntityInfoIter->second;
00266       TGeom2Size::iterator aGeomIter = aGeom2Size.begin();
00267       for(; aGeomIter != aGeom2Size.end(); aGeomIter++){
00268         const EGeometrieElement& aGeom = aGeomIter->first;
00269 #ifdef _DEBUG_
00270         const TInt& aNbElem = aGeomIter->second;
00271         INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<": ");
00272 #endif
00273         switch(aGeom){
00274         case ePOLYGONE: {
00275           PPolygoneInfo aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
00276           PPolygoneInfo aPolygoneInfo2 = theMed->CrPolygoneInfo(aMeshInfo2,aPolygoneInfo);
00277           if(MYWRITEDEBUG) theMed2->SetPolygoneInfo(aPolygoneInfo2);
00278           break;
00279         }
00280         case ePOLYEDRE: {
00281           PPolyedreInfo aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
00282           PPolyedreInfo aPolyedreInfo2 = theMed->CrPolyedreInfo(aMeshInfo2,aPolyedreInfo);
00283           if(MYWRITEDEBUG) theMed2->SetPolyedreInfo(aPolyedreInfo2);
00284           break;
00285         }
00286         default:
00287           PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
00288           PCellInfo aCellInfo2 = theMed2->CrCellInfo(aMeshInfo2,aCellInfo);
00289           if(MYWRITEDEBUG) theMed2->SetCellInfo(aCellInfo2);
00290         }
00291       }
00292     }
00293     
00294   }
00295   MSG(MYDEBUG,"OK");
00296 }
00297 
00298 
00299 void CopyMed(const std::string& theFileName, 
00300              const std::string& theFileName2, 
00301              MED::EVersion theVersion,
00302              int theNbCopy)
00303 {
00304   MSG(MYDEBUG,"CopyMed - theFileName = '"<<theFileName<<"'; theFileName2 = '"<<theFileName2<<"', theVersion = "<<theVersion);
00305 
00306   PWrapper aMed = CrWrapper(theFileName);
00307 
00308   PWrapper aMed2 = CrWrapper(theFileName2,theVersion);
00309 
00310   for(int i = 0; i < theNbCopy; i++) 
00311     CopyMed(aMed,aMed2,i);
00312 }
00313 
00314 
00315 void ReadMed(const char* theFileName, 
00316              const char* theFileName2,
00317              MED::EVersion theVersion = eV2_2,
00318              int theNbCopy = 1)
00319 {
00320   MSG(MYDEBUG,"theFileName = '"<<theFileName<<"'; "<<
00321       "theFileName2 = '"<<theFileName2<<"'; "<<
00322       "theVersion = "<<theVersion<<"; "<<
00323       "theNbCopy = "<<theNbCopy);
00324 
00325   CopyMed(theFileName,theFileName2,theVersion,theNbCopy);
00326 }
00327 
00328 #ifdef WNT
00329 #pragma warning(disable:4101) // exc unreferenced ... ??
00330 #endif
00331 
00332 int main(int argc, char** argv){ 
00333 #ifndef _DEBUG_
00334   try{
00335 #endif
00336     if(argc == 2)
00337       CheckMed(argv[1]);
00338     if(argc == 3)
00339       ReadMed(argv[1],argv[2]);
00340     if(argc == 4)
00341       ReadMed(argv[1],argv[2],MED::EVersion(atoi(argv[3])));
00342     if(argc == 5)
00343       ReadMed(argv[1],argv[2],MED::EVersion(atoi(argv[3])),atoi(argv[4]));
00344     return 0;
00345 #ifndef _DEBUG_
00346   }catch(std::exception& exc){
00347     MSG(MYDEBUG,"Follow exception was accured :\n"<<exc.what());
00348   }catch(...){
00349     MSG(MYDEBUG,"Unknown exception was accured");
00350   } 
00351 #endif 
00352   return 1;
00353 }