1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MED_Utilities.hxx"
23 #include "MED_Algorithm.hxx"
24 #include "MED_GaussUtils.hxx"
25 #include "MED_Factory.hxx"
28 static int MYDEBUG = 1;
30 // static int MYDEBUG = 0;
33 static int MYWRITEDEBUG = 1;
39 void CheckMed(const std::string& theFileName)
41 MSG(MYDEBUG,"CheckMed - theFileName = '"<<theFileName<<"'");
44 PWrapper aMed = CrWrapper(theFileName);
46 TKey2Gauss aKey2Gauss = GetKey2Gauss(aMed);
47 TMKey2Profile aMKey2Profile = GetMKey2Profile(aMed);
48 INITMSG(MYDEBUG,"aMed->GetNbProfiles() = "<<aMed->GetNbProfiles()<<std::endl);
50 TInt aNbMeshes = aMed->GetNbMeshes();
51 BEGMSG(MYDEBUG,"GetNbMeshes() = "<<aNbMeshes<<std::endl);
52 for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
54 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
55 INITMSG(MYDEBUG,"aMeshInfo->GetName() = '"<<aMeshInfo->GetName()<<"'"<<std::endl);
57 TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
59 TEntity2TGeom2ElemInfo anEntity2TGeom2ElemInfo =
60 GetEntity2TGeom2ElemInfo(aMed,aMeshInfo,aEntityInfo);
62 TFieldInfo2TimeStampInfoSet aFieldInfo2TimeStampInfoSet =
63 GetFieldInfo2TimeStampInfoSet(aMed,aMeshInfo,aEntityInfo);
65 TEntite2TFieldInfo2TimeStampInfoSet anEntite2TFieldInfo2TimeStampInfoSet =
66 GetEntite2TFieldInfo2TimeStampInfoSet(aFieldInfo2TimeStampInfoSet);
68 TEntite2TFieldInfo2TimeStampInfoSet::const_iterator anEntite2TFieldInfo2TimeStampInfoSetIter =
69 anEntite2TFieldInfo2TimeStampInfoSet.begin();
70 for(; anEntite2TFieldInfo2TimeStampInfoSetIter != anEntite2TFieldInfo2TimeStampInfoSet.end(); anEntite2TFieldInfo2TimeStampInfoSetIter++){
71 const TFieldInfo2TimeStampInfoSet& aFieldInfo2TimeStampInfoSet = anEntite2TFieldInfo2TimeStampInfoSetIter->second;
72 TFieldInfo2TimeStampInfoSet::const_iterator aFieldInfo2TimeStampInfoSetIter = aFieldInfo2TimeStampInfoSet.begin();
73 for(; aFieldInfo2TimeStampInfoSetIter != aFieldInfo2TimeStampInfoSet.end(); aFieldInfo2TimeStampInfoSetIter++){
74 PFieldInfo aFieldInfo = aFieldInfo2TimeStampInfoSetIter->first;
77 "- aName = '"<<aFieldInfo->GetName()<<"'"<<
78 "; aType = "<<aFieldInfo->GetType()<<
79 "; aNbComp = "<<aFieldInfo->GetNbComp()<<
81 const TTimeStampInfoSet& aTimeStampInfoSet = aFieldInfo2TimeStampInfoSetIter->second;
82 TTimeStampInfoSet::const_iterator aTimeStampInfoSettIter = aTimeStampInfoSet.begin();
83 for(; aTimeStampInfoSettIter != aTimeStampInfoSet.end(); aTimeStampInfoSettIter++){
84 PTimeStampInfo aTimeStampInfo = *aTimeStampInfoSettIter;
86 "GetPTimeStampInfo "<<
87 "- anEntity = "<<aTimeStampInfo->GetEntity()<<
88 "; aNumDt = "<<aTimeStampInfo->GetNumDt()<<
90 PTimeStampValueBase aTimeStampValue =
91 aMed->GetPTimeStampValue(aTimeStampInfo,
100 TFamilyInfoSet aFamilyInfoSet = GetFamilyInfoSet(aMed,aMeshInfo);
102 TEntity2FamilySet aEntity2FamilySet =
103 GetEntity2FamilySet(aMed,anEntity2TGeom2ElemInfo,aFamilyInfoSet);
105 TGroupInfo aGroupInfo = GetGroupInfo(aFamilyInfoSet);
107 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
108 TEntity2TGeom2ElemInfo::const_iterator anIter = anEntity2TGeom2ElemInfo.begin();
109 for(; anIter != anEntity2TGeom2ElemInfo.end(); anIter++){
110 const EEntiteMaillage& anEntity = anIter->first;
111 if(anEntity != eNOEUD){
112 const TGeom2ElemInfo& aGeom2ElemInfo = anIter->second;
113 TKey2Gauss::const_iterator anIter2 = aKey2Gauss.begin();
114 for(; anIter2 != aKey2Gauss.end(); anIter2++){
115 const TGaussInfo::TKey& aKey = anIter2->first;
116 EGeometrieElement aGeom = boost::get<0>(aKey);
117 TGeom2ElemInfo::const_iterator anIter3 = aGeom2ElemInfo.find(aGeom);
118 if(anIter3 != aGeom2ElemInfo.end()){
119 if(PCellInfo aCellInfo = anIter3->second){
120 PGaussInfo aGaussInfo = anIter2->second;
121 TGaussCoord aGaussCoord;
122 GetGaussCoord3D(aGaussInfo,aCellInfo,aNodeInfo,aGaussCoord);
135 void CopyMed(const PWrapper& theMed,
136 const PWrapper& theMed2,
139 TKey2Gauss aKey2Gauss = GetKey2Gauss(theMed);
140 TMKey2Profile aMKey2Profile = GetMKey2Profile(theMed);
142 TInt aNbMeshes = theMed->GetNbMeshes();
143 MSG(MYDEBUG,"aNbMeshes = "<<aNbMeshes);
145 for(TInt iMesh = 0; iMesh < aNbMeshes; iMesh++){
146 PMeshInfo aMeshInfo = theMed->GetPMeshInfo(iMesh+1);
148 TInt aDim = aMeshInfo->myDim;
149 aName = aMeshInfo->GetName();
150 INITMSG(MYDEBUG,"GetMeshInfo - aName = '"<<aName<<"'; aDim = "<<aDim<<"\n");
152 PMeshInfo aMeshInfo2 = theMed2->CrMeshInfo(aMeshInfo);
154 aName = aMeshInfo2->GetName();
157 aMeshInfo2->SetName(aName);
158 theMed2->SetMeshInfo(aMeshInfo2);
159 BEGMSG(MYDEBUG,"aNbMeshes2 = "<<theMed2->GetNbMeshes()<<"\n");
162 TEntityInfo aEntityInfo = theMed->GetEntityInfo(aMeshInfo);
166 TInt aNbFields = theMed->GetNbFields();
167 MSG(MYDEBUG,"GetNbFields() = "<<aNbFields);
168 for(TInt iField = 0; iField < aNbFields; iField++){
169 PFieldInfo aFieldInfo = theMed->GetPFieldInfo(aMeshInfo,iField+1);
171 TInt aNbComp = aFieldInfo->GetNbComp();
172 INITMSG(MYDEBUG,"aName = '"<<aFieldInfo->GetName()<<"'; aNbComp = "<<aNbComp<<";\n");
174 PFieldInfo aFieldInfo2 = theMed->CrFieldInfo(aMeshInfo2,aFieldInfo);
177 aName = aFieldInfo->GetName();
179 aFieldInfo2->SetName(aName);
180 theMed2->SetFieldInfo(aFieldInfo2);
183 EEntiteMaillage anEntity;
184 TGeom2Size aGeom2Size;
186 theMed->GetNbTimeStamps(aFieldInfo,aEntityInfo,anEntity,aGeom2Size);
188 INITMSG(MYDEBUG,"GetNbTimeStamps = "<<aNbTimeStamps<<std::endl);
189 for(TInt iTimeStamp = 0; iTimeStamp < aNbTimeStamps; iTimeStamp++){
190 PTimeStampInfo aTimeStampInfo =
191 theMed->GetPTimeStampInfo(aFieldInfo,anEntity,aGeom2Size,iTimeStamp+1);
193 TInt aNumDt = aTimeStampInfo->GetNumDt();
194 INITMSG(MYDEBUG,"aNumDt = "<<aNumDt<<"\n");
197 PTimeStampInfo aTimeStampInfo2 =
198 theMed->CrTimeStampInfo(aFieldInfo2,aTimeStampInfo);
200 PTimeStampValueBase aTimeStampValue =
201 theMed->GetPTimeStampValue(aTimeStampInfo,
205 PTimeStampValueBase aTimeStampValue2 =
206 theMed->CrTimeStampValue(aTimeStampInfo2,
209 if(MYWRITEDEBUG) theMed2->SetTimeStamp(aTimeStampValue2);
214 TInt aNbFam = theMed->GetNbFamilies(aMeshInfo);
215 MSG(MYDEBUG,"GetNbFamilies() = "<<aNbFam);
216 for(TInt iFam = 0; iFam < aNbFam; iFam++){
217 PFamilyInfo aFamilyInfo = theMed->GetPFamilyInfo(aMeshInfo,iFam+1);
218 TInt aNbGroup = aFamilyInfo->GetNbGroup();
220 TInt aNbAttr = aFamilyInfo->GetNbAttr();
222 TInt anId = aFamilyInfo->GetId();
226 aName = aFamilyInfo->GetName();
228 INITMSG(MYDEBUG,"aName = '"<<aName<<"'; anId = "<<anId<<
229 "; aNbAttr = "<<aNbAttr<<"; aNbGroup = "<<aNbGroup<<"\n");
231 PFamilyInfo aFamilyInfo2 = theMed->CrFamilyInfo(aMeshInfo2,aFamilyInfo);
232 for(TInt iGroup = 0; iGroup < aNbGroup; iGroup++){
233 aName = aFamilyInfo->GetGroupName(iGroup);
234 INITMSG(MYDEBUG,"aGroupName = '"<<aName<<"'\n");
236 aFamilyInfo2->SetGroupName(iGroup,aName);
240 aName = aFamilyInfo->GetName();
242 aFamilyInfo2->SetName(aName);
243 theMed2->SetFamilyInfo(aFamilyInfo2);
244 INITMSG(MYDEBUG,"GetNbFamilies = "<<theMed2->GetNbFamilies(aMeshInfo2)<<std::endl);
248 MSG(MYDEBUG,"GetEntityInfo - aNbEntities = "<<aEntityInfo.size());
249 TEntityInfo::iterator anEntityInfoIter = aEntityInfo.begin();
250 for(; anEntityInfoIter != aEntityInfo.end(); anEntityInfoIter++){
251 const EEntiteMaillage& anEntity = anEntityInfoIter->first;
252 INITMSG(MYDEBUG,"anEntity = "<<anEntity<<"\n");
253 if(anEntity == eNOEUD){
254 PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
255 PNodeInfo aNodeInfo2 = theMed->CrNodeInfo(aMeshInfo2,aNodeInfo);
256 if(MYWRITEDEBUG) theMed2->SetNodeInfo(aNodeInfo2);
259 TGeom2Size& aGeom2Size = anEntityInfoIter->second;
260 TGeom2Size::iterator aGeomIter = aGeom2Size.begin();
261 for(; aGeomIter != aGeom2Size.end(); aGeomIter++){
262 const EGeometrieElement& aGeom = aGeomIter->first;
264 const TInt& aNbElem = aGeomIter->second;
265 INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<": ");
269 PPolygoneInfo aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
270 PPolygoneInfo aPolygoneInfo2 = theMed->CrPolygoneInfo(aMeshInfo2,aPolygoneInfo);
271 if(MYWRITEDEBUG) theMed2->SetPolygoneInfo(aPolygoneInfo2);
275 PPolyedreInfo aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
276 PPolyedreInfo aPolyedreInfo2 = theMed->CrPolyedreInfo(aMeshInfo2,aPolyedreInfo);
277 if(MYWRITEDEBUG) theMed2->SetPolyedreInfo(aPolyedreInfo2);
281 PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
282 PCellInfo aCellInfo2 = theMed2->CrCellInfo(aMeshInfo2,aCellInfo);
283 if(MYWRITEDEBUG) theMed2->SetCellInfo(aCellInfo2);
293 void CopyMed(const std::string& theFileName,
294 const std::string& theFileName2,
295 MED::EVersion theVersion,
298 MSG(MYDEBUG,"CopyMed - theFileName = '"<<theFileName<<"'; theFileName2 = '"<<theFileName2<<"', theVersion = "<<theVersion);
300 PWrapper aMed = CrWrapper(theFileName);
302 PWrapper aMed2 = CrWrapper(theFileName2,theVersion);
304 for(int i = 0; i < theNbCopy; i++)
305 CopyMed(aMed,aMed2,i);
309 void ReadMed(const char* theFileName,
310 const char* theFileName2,
311 MED::EVersion theVersion = eV2_2,
314 MSG(MYDEBUG,"theFileName = '"<<theFileName<<"'; "<<
315 "theFileName2 = '"<<theFileName2<<"'; "<<
316 "theVersion = "<<theVersion<<"; "<<
317 "theNbCopy = "<<theNbCopy);
319 CopyMed(theFileName,theFileName2,theVersion,theNbCopy);
323 #pragma warning(disable:4101) // exc unreferenced ... ??
326 int main(int argc, char** argv){
333 ReadMed(argv[1],argv[2]);
335 ReadMed(argv[1],argv[2],MED::EVersion(atoi(argv[3])));
337 ReadMed(argv[1],argv[2],MED::EVersion(atoi(argv[3])),atoi(argv[4]));
340 }catch(std::exception& exc){
341 MSG(MYDEBUG,"Follow exception was accured :\n"<<exc.what());
343 MSG(MYDEBUG,"Unknown exception was accured");