3 // Copyright (C) 2003 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.
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
29 #include "MED_Utilities.hxx"
30 #include "MED_Algorithm.hxx"
31 #include "MED_Factory.hxx"
34 static int MYDEBUG = 1;
36 static int MYDEBUG = 0;
39 static int MYVALUEDEBUG = 0;
41 static int MYWRITEDEBUG = 1;
46 void CheckMed(const std::string& theFileName)
48 MSG(MYDEBUG,"CheckMed - theFileName = '"<<theFileName<<"'");
50 PWrapper aMed = CrWrapper(theFileName);
51 TInt aNbMeshes = aMed->GetNbMeshes();
52 INITMSG(MYDEBUG,"GetNbMeshes() = "<<aNbMeshes<<endl);
53 for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
55 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
56 INITMSG(MYDEBUG,"aMeshInfo->GetName() = "<<aMeshInfo->GetName()<<endl);
60 TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
62 TElemGroup aElemGroup = GetElemsByEntity(aMed,aMeshInfo,aEntityInfo);
64 TFamilyGroup aFamilyGroup = GetFamilies(aMed,aMeshInfo);
66 TFamilyByEntity aFamilyByEntity = GetFamiliesByEntity(aMed,aElemGroup,aFamilyGroup);
68 TGroupInfo aGroupInfo = GetFamiliesByGroup(aFamilyGroup);
70 TTimeStampGroup aTimeStampGroup = GetFieldsByEntity(aMed,aMeshInfo,aEntityInfo);
72 TFieldGroup aFieldGroup = GetFieldsByEntity(aTimeStampGroup);
74 TFieldGroup::const_iterator aFieldGroupIter = aFieldGroup.begin();
75 for(; aFieldGroupIter != aFieldGroup.end(); aFieldGroupIter++){
76 const TTimeStampGroup& aTTimeStampGroup = aFieldGroupIter->second;
77 TTimeStampGroup::const_iterator aTTimeStampGroupIter = aTTimeStampGroup.begin();
78 for(; aTTimeStampGroupIter != aTTimeStampGroup.end(); aTTimeStampGroupIter++){
79 PFieldInfo aFieldInfo = aTTimeStampGroupIter->first;
80 const TTimeStampSet& aTimeStampSet = aTTimeStampGroupIter->second;
81 TTimeStampSet::const_iterator aTTimeStampSetIter = aTimeStampSet.begin();
82 for(; aTTimeStampSetIter != aTimeStampSet.end(); aTTimeStampSetIter++){
83 PTimeStampInfo aTimeStampInfo = *aTTimeStampSetIter;
85 PTimeStampVal aTimeStampVal = aMed->GetPTimeStampVal(aTimeStampInfo,&anErr);
96 void CopyMed(const PWrapper& theMed,
97 const PWrapper& theMed2,
100 TInt aNbMeshes = theMed->GetNbMeshes();
101 MSG(MYDEBUG,"aNbMeshes = "<<aNbMeshes);
103 for(TInt iMesh = 0; iMesh < aNbMeshes; iMesh++){
104 PMeshInfo aMeshInfo = theMed->GetPMeshInfo(iMesh+1);
105 TInt aDim = aMeshInfo->myDim;
106 aName = aMeshInfo->GetName();
107 INITMSG(MYDEBUG,"GetMeshInfo - aName = '"<<aName<<"'; aDim = "<<aDim<<"\n");
108 PMeshInfo aMeshInfo2 = theMed2->CrMeshInfo(aMeshInfo);
110 aName = aMeshInfo2->GetName();
113 aMeshInfo2->SetName(aName);
114 theMed2->SetMeshInfo(aMeshInfo2);
115 BEGMSG(MYDEBUG,"aNbMeshes2 = "<<theMed2->GetNbMeshes()<<"\n");
118 TEntityInfo aEntityInfo = theMed->GetEntityInfo(aMeshInfo);
122 TInt aNbFields = theMed->GetNbFields();
123 MSG(MYDEBUG,"GetNbFields() = "<<aNbFields);
124 for(TInt iField = 0; iField < aNbFields; iField++){
125 PFieldInfo aFieldInfo = theMed->GetPFieldInfo(aMeshInfo,iField+1);
126 TInt aNbComp = aFieldInfo->GetNbComp();
127 INITMSG(MYDEBUG,"aName = '"<<aFieldInfo->GetName()<<"'; aNbComp = "<<aNbComp<<";\n");
128 PFieldInfo aFieldInfo2 = theMed->CrFieldInfo(aMeshInfo2,aFieldInfo);
131 aName = aFieldInfo->GetName();
133 aFieldInfo2->SetName(aName);
134 theMed2->SetFieldInfo(aFieldInfo2);
137 EEntiteMaillage anEntity;
140 theMed->GetNbTimeStamps(aFieldInfo,aEntityInfo,anEntity,aTGeom);
142 INITMSG(MYDEBUG,"GetNbTimeStamps = "<<aNbTimeStamps<<endl);
143 for(TInt iTimeStamp = 0; iTimeStamp < aNbTimeStamps; iTimeStamp++){
144 PTimeStampInfo aTimeStampInfo =
145 theMed->GetPTimeStampInfo(aFieldInfo,anEntity,aTGeom,iTimeStamp+1);
146 TInt aNumDt = aTimeStampInfo->GetNumDt();
147 TInt aNbGauss = aTimeStampInfo->GetNbGauss();
148 INITMSG(MYDEBUG,"aNbGauss = "<<aNbGauss<<"; aNumDt = "<<aNumDt<<"\n");
150 PTimeStampInfo aTimeStampInfo2 =
151 theMed->CrTimeStampInfo(aFieldInfo2,aTimeStampInfo);
153 PTimeStampVal aTimeStampVal = theMed->GetPTimeStampVal(aTimeStampInfo);
155 PTimeStampVal aTimeStampVal2 = theMed->CrTimeStampVal(aTimeStampInfo2,aTimeStampVal);
157 if(MYWRITEDEBUG) theMed2->SetTimeStamp(aTimeStampVal2);
159 TMeshValue& aMeshValue = aTimeStampVal->myMeshValue;
160 TMeshValue::iterator aMeshValueIter = aMeshValue.begin();
161 for(; aMeshValueIter != aMeshValue.end(); aMeshValueIter++){
162 EGeometrieElement aGeom = aMeshValueIter->first;
163 TValue aValue = aMeshValueIter->second;
164 INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aValue = "<<aValue.size()<<": ");
165 for(TInt i = 0, iEnd = aValue.size()/aNbComp; i < iEnd; i++){
166 for(TInt j = 0, ij = i*aNbComp; j < aNbComp; j++, ij++){
167 ADDMSG(MYVALUEDEBUG,aValue[ij]<<",");
169 ADDMSG(MYVALUEDEBUG," ");
171 ADDMSG(MYDEBUG,"\n");
177 TInt aNbFam = theMed->GetNbFamilies(aMeshInfo);
178 MSG(MYDEBUG,"GetNbFamilies() = "<<aNbFam);
179 for(TInt iFam = 0; iFam < aNbFam; iFam++){
180 PFamilyInfo aFamilyInfo = theMed->GetPFamilyInfo(aMeshInfo,iFam+1);
181 TInt aNbGroup = aFamilyInfo->GetNbGroup();
182 TInt aNbAttr = aFamilyInfo->GetNbAttr();
183 TInt anId = aFamilyInfo->GetId();
187 aName = aFamilyInfo->GetName();
188 INITMSG(MYDEBUG,"aName = '"<<aName<<"'; anId = "<<anId<<
189 "; aNbAttr = "<<aNbAttr<<"; aNbGroup = "<<aNbGroup<<"\n");
190 PFamilyInfo aFamilyInfo2 = theMed->CrFamilyInfo(aMeshInfo2,aFamilyInfo);
191 for(TInt iGroup = 0; iGroup < aNbGroup; iGroup++){
192 aName = aFamilyInfo->GetGroupName(iGroup);
193 INITMSG(MYDEBUG,"aGroupName = '"<<aName<<"'\n");
195 aFamilyInfo2->SetGroupName(iGroup,aName);
199 aName = aFamilyInfo->GetName();
201 aFamilyInfo2->SetName(aName);
202 theMed2->SetFamilyInfo(aFamilyInfo2);
203 INITMSG(MYDEBUG,"GetNbFamilies = "<<theMed2->GetNbFamilies(aMeshInfo2)<<endl);
207 MSG(MYDEBUG,"GetEntityInfo - aNbEntities = "<<aEntityInfo.size());
208 TEntityInfo::iterator anEntityInfoIter = aEntityInfo.begin();
209 for(; anEntityInfoIter != aEntityInfo.end(); anEntityInfoIter++){
210 const EEntiteMaillage& anEntity = anEntityInfoIter->first;
211 INITMSG(MYDEBUG,"anEntity = "<<anEntity<<"\n");
212 if(anEntity == eNOEUD){
213 PNodeInfo aNodeInfo = theMed->GetPNodeInfo(aMeshInfo);
214 PNodeInfo aNodeInfo2 = theMed->CrNodeInfo(aMeshInfo2,aNodeInfo);
215 if(MYWRITEDEBUG) theMed2->SetNodeInfo(aNodeInfo2);
218 TGeom& aTGeom = anEntityInfoIter->second;
219 TGeom::iterator anTGeomIter = aTGeom.begin();
220 for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
221 const EGeometrieElement& aGeom = anTGeomIter->first;
222 const TInt& aNbElem = anTGeomIter->second;
223 INITMSG(MYDEBUG,"aGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<": ");
227 PPolygoneInfo aPolygoneInfo = theMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
228 TElemNum aConn = aPolygoneInfo->GetConnectivite();
229 TElemNum aIndex = aPolygoneInfo->GetIndex();
230 TInt aNbIndex = aIndex.size();
231 TInt aIndex0 = aIndex[0];
232 for(TInt iElem = 1; iElem < aNbIndex; iElem++){
233 for (TInt i = aIndex0; i < aIndex[iElem];i++)
234 ADDMSG(MYVALUEDEBUG,aConn[i-1]<<",");
236 aIndex0 = aIndex[iElem];
238 ADDMSG(MYDEBUG,endl);
239 INITMSG(MYDEBUG,"Indexes :");
240 for(TInt iElem = 0; iElem < aIndex.size(); iElem++){
241 ADDMSG(MYVALUEDEBUG,aIndex[iElem]<<",");
243 ADDMSG(MYDEBUG,endl);
244 PPolygoneInfo aPolygoneInfo2 = theMed->CrPolygoneInfo(aMeshInfo2,aPolygoneInfo);
245 if(MYWRITEDEBUG) theMed2->SetPolygoneInfo(aPolygoneInfo2);
250 PPolyedreInfo aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
251 TElemNum aConn = aPolyedreInfo->GetConnectivite();
252 TElemNum aFacesIndex = aPolyedreInfo->GetFacesIndex();
253 TElemNum aIndex = aPolyedreInfo->GetIndex();
255 TInt aNbIndex = aIndex.size();
257 for (int aNp = 0; aNp < aNbIndex-1;aNp++){
258 if (aPolyedreInfo->IsElemNames())
259 ADDMSG(MYDEBUG,aPolyedreInfo->GetElemName(aNp)<<endl);
261 ADDMSG(MYDEBUG,"POLYEDRE "<<aNp+1<<endl);
263 for (int aNf = aIndex[aNp]-1;aNf < aIndex[aNp+1]-1;aNf++){
264 ADDMSG(MYDEBUG,"Face "<<aNf-aIndex[aNp]+2<<": [");
265 for (int aNc = aFacesIndex[aNf]-1; aNc < aFacesIndex[aNf+1]-1;aNc++){
266 ADDMSG(MYDEBUG," "<<aConn[aNc]);
268 ADDMSG(MYDEBUG," ]"<<endl;);
272 PPolyedreInfo aPolyedreInfo2 = theMed->CrPolyedreInfo(aMeshInfo2,aPolyedreInfo);
273 if(MYWRITEDEBUG) theMed2->SetPolyedreInfo(aPolyedreInfo2);
277 PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
278 PCellInfo aCellInfo2 = theMed2->CrCellInfo(aMeshInfo2,aCellInfo);
279 if(MYWRITEDEBUG) theMed2->SetCellInfo(aCellInfo2);
289 void CopyMed(const std::string& theFileName,
290 const std::string& theFileName2,
291 MED::EVersion theVersion,
294 MSG(MYDEBUG,"CopyMed - theFileName = '"<<theFileName<<"'; theFileName2 = '"<<theFileName2<<"', theVersion = "<<theVersion);
296 PWrapper aMed = CrWrapper(theFileName);
298 PWrapper aMed2 = CrWrapper(theFileName2,theVersion);
300 for(int i = 0; i < theNbCopy; i++)
301 CopyMed(aMed,aMed2,i);
305 void ReadMed(const char* theFileName,
306 const char* theFileName2,
307 MED::EVersion theVersion = eV2_2,
310 MSG(MYDEBUG,"theFileName = '"<<theFileName<<"'; "<<
311 "theFileName2 = '"<<theFileName2<<"'; "<<
312 "theVersion = "<<theVersion<<"; "<<
313 "theNbCopy = "<<theNbCopy);
315 CopyMed(theFileName,theFileName2,theVersion,theNbCopy);
319 int main(int argc, char** argv){
324 ReadMed(argv[1],argv[2]);
326 ReadMed(argv[1],argv[2],MED::EVersion(atoi(argv[3])));
328 ReadMed(argv[1],argv[2],MED::EVersion(atoi(argv[3])),atoi(argv[4]));
330 }catch(std::exception& exc){
331 MSG(MYDEBUG,"Follow exception was accured :\n"<<exc.what());
333 MSG(MYDEBUG,"Unknown exception was accured");