]> SALOME platform Git repositories - modules/med.git/blob - src/MEDWrapper/Factory/MED_Test.cxx
Salome HOME
update after merging trhe branches CEA_V3_0_x, OCC_V3_1_0_a1_x, and the main
[modules/med.git] / src / MEDWrapper / Factory / MED_Test.cxx
1 //  
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : 
25 //  Author : 
26 //  Module : 
27 //  $Header$
28
29 #include "MED_Utilities.hxx"
30 #include "MED_Algorithm.hxx"
31 #include "MED_Factory.hxx"
32
33 #ifdef _DEBUG_
34 static int MYDEBUG = 1;
35 #else
36 static int MYDEBUG = 0;
37 #endif
38
39 static int MYVALUEDEBUG = 0;
40
41 static int MYWRITEDEBUG = 1;
42
43 using namespace MED;
44
45
46 void CheckMed(const std::string& theFileName)
47 {
48   MSG(MYDEBUG,"CheckMed - theFileName = '"<<theFileName<<"'");
49   {
50     PWrapper aMed = CrWrapper(theFileName);
51     TInt aNbMeshes = aMed->GetNbMeshes();
52     INITMSG(MYDEBUG,"GetNbMeshes() = "<<aNbMeshes<<endl);
53     for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){
54       
55       PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh);
56       INITMSG(MYDEBUG,"aMeshInfo->GetName() = "<<aMeshInfo->GetName()<<endl);
57
58       //continue;
59
60       TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
61       
62       TElemGroup aElemGroup = GetElemsByEntity(aMed,aMeshInfo,aEntityInfo);
63       
64       TFamilyGroup aFamilyGroup = GetFamilies(aMed,aMeshInfo);
65       
66       TFamilyByEntity aFamilyByEntity = GetFamiliesByEntity(aMed,aElemGroup,aFamilyGroup);
67       
68       TGroupInfo aGroupInfo = GetFamiliesByGroup(aFamilyGroup);
69       
70       TTimeStampGroup aTimeStampGroup = GetFieldsByEntity(aMed,aMeshInfo,aEntityInfo);
71       
72       TFieldGroup aFieldGroup = GetFieldsByEntity(aTimeStampGroup);
73
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;
84             TErr anErr;
85             PTimeStampVal aTimeStampVal = aMed->GetPTimeStampVal(aTimeStampInfo,&anErr);
86           }
87         }
88       }
89
90     }
91   }
92   MSG(MYDEBUG,"OK");
93 }
94
95
96 void CopyMed(const PWrapper& theMed, 
97              const PWrapper& theMed2, 
98              int theIncr)
99 {
100   TInt aNbMeshes = theMed->GetNbMeshes();
101   MSG(MYDEBUG,"aNbMeshes = "<<aNbMeshes);
102   std::string aName;
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);
109     if(MYWRITEDEBUG){
110       aName = aMeshInfo2->GetName();
111
112       aName[0] += theIncr;
113       aMeshInfo2->SetName(aName);
114       theMed2->SetMeshInfo(aMeshInfo2);
115       BEGMSG(MYDEBUG,"aNbMeshes2 = "<<theMed2->GetNbMeshes()<<"\n");
116     }
117     
118     TEntityInfo aEntityInfo = theMed->GetEntityInfo(aMeshInfo);
119
120     //continue;
121
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);
129
130       if(MYWRITEDEBUG){
131         aName = aFieldInfo->GetName();
132         aName[0] += theIncr;
133         aFieldInfo2->SetName(aName);
134         theMed2->SetFieldInfo(aFieldInfo2);
135       }
136
137       EEntiteMaillage anEntity;
138       TGeom aTGeom;
139       TInt aNbTimeStamps = 
140         theMed->GetNbTimeStamps(aFieldInfo,aEntityInfo,anEntity,aTGeom);
141       {
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");
149           
150           PTimeStampInfo aTimeStampInfo2 = 
151             theMed->CrTimeStampInfo(aFieldInfo2,aTimeStampInfo);
152           
153           PTimeStampVal aTimeStampVal = theMed->GetPTimeStampVal(aTimeStampInfo);
154           
155           PTimeStampVal aTimeStampVal2 = theMed->CrTimeStampVal(aTimeStampInfo2,aTimeStampVal);
156           
157           if(MYWRITEDEBUG) theMed2->SetTimeStamp(aTimeStampVal2);
158           
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]<<",");
168               }
169               ADDMSG(MYVALUEDEBUG," ");
170             }
171             ADDMSG(MYDEBUG,"\n");
172           }
173         }
174       }
175     }
176
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();
184       if(anId == 0)
185         continue;
186
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");
194         aName[0] += theIncr;
195         aFamilyInfo2->SetGroupName(iGroup,aName);
196       }
197
198       if(MYWRITEDEBUG){
199         aName = aFamilyInfo->GetName();
200         aName[0] += theIncr;
201         aFamilyInfo2->SetName(aName);
202         theMed2->SetFamilyInfo(aFamilyInfo2);
203         INITMSG(MYDEBUG,"GetNbFamilies = "<<theMed2->GetNbFamilies(aMeshInfo2)<<endl);
204       }
205     }
206
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);
216         continue;
217       }
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<<": ");
224         switch(aGeom){
225         case ePOLYGONE:
226           {
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]<<",");
235               ADDMSG(MYDEBUG," ");
236               aIndex0 = aIndex[iElem];
237             }
238             ADDMSG(MYDEBUG,endl);
239             INITMSG(MYDEBUG,"Indexes :");
240             for(TInt iElem = 0; iElem < aIndex.size(); iElem++){
241               ADDMSG(MYVALUEDEBUG,aIndex[iElem]<<",");
242             }
243             ADDMSG(MYDEBUG,endl);
244             PPolygoneInfo aPolygoneInfo2 = theMed->CrPolygoneInfo(aMeshInfo2,aPolygoneInfo);
245             if(MYWRITEDEBUG) theMed2->SetPolygoneInfo(aPolygoneInfo2);
246             break;
247           }
248         case ePOLYEDRE:
249           {
250             PPolyedreInfo aPolyedreInfo = theMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
251             TElemNum aConn        = aPolyedreInfo->GetConnectivite();
252             TElemNum aFacesIndex  = aPolyedreInfo->GetFacesIndex();
253             TElemNum aIndex       = aPolyedreInfo->GetIndex();
254             
255             TInt aNbIndex      = aIndex.size();
256             
257             for (int aNp = 0; aNp < aNbIndex-1;aNp++){
258               if (aPolyedreInfo->IsElemNames())
259                 ADDMSG(MYDEBUG,aPolyedreInfo->GetElemName(aNp)<<endl);
260               else 
261                 ADDMSG(MYDEBUG,"POLYEDRE "<<aNp+1<<endl);
262
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]);
267                 }
268                 ADDMSG(MYDEBUG," ]"<<endl;);
269               }
270             }
271
272             PPolyedreInfo aPolyedreInfo2 = theMed->CrPolyedreInfo(aMeshInfo2,aPolyedreInfo);
273             if(MYWRITEDEBUG) theMed2->SetPolyedreInfo(aPolyedreInfo2);
274             break;
275           }
276         default:
277           PCellInfo aCellInfo = theMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
278           PCellInfo aCellInfo2 = theMed2->CrCellInfo(aMeshInfo2,aCellInfo);
279           if(MYWRITEDEBUG) theMed2->SetCellInfo(aCellInfo2);
280         }
281       }
282     }
283     
284   }
285   MSG(MYDEBUG,"OK");
286 }
287
288
289 void CopyMed(const std::string& theFileName, 
290              const std::string& theFileName2, 
291              MED::EVersion theVersion,
292              int theNbCopy)
293 {
294   MSG(MYDEBUG,"CopyMed - theFileName = '"<<theFileName<<"'; theFileName2 = '"<<theFileName2<<"', theVersion = "<<theVersion);
295
296   PWrapper aMed = CrWrapper(theFileName);
297
298   PWrapper aMed2 = CrWrapper(theFileName2,theVersion);
299
300   for(int i = 0; i < theNbCopy; i++) 
301     CopyMed(aMed,aMed2,i);
302 }
303
304
305 void ReadMed(const char* theFileName, 
306              const char* theFileName2,
307              MED::EVersion theVersion = eV2_2,
308              int theNbCopy = 1)
309 {
310   MSG(MYDEBUG,"theFileName = '"<<theFileName<<"'; "<<
311       "theFileName2 = '"<<theFileName2<<"'; "<<
312       "theVersion = "<<theVersion<<"; "<<
313       "theNbCopy = "<<theNbCopy);
314
315   CopyMed(theFileName,theFileName2,theVersion,theNbCopy);
316 }
317
318
319 int main(int argc, char** argv){ 
320   try{
321     if(argc == 2)
322       CheckMed(argv[1]);
323     if(argc == 3)
324       ReadMed(argv[1],argv[2]);
325     if(argc == 4)
326       ReadMed(argv[1],argv[2],MED::EVersion(atoi(argv[3])));
327     if(argc == 5)
328       ReadMed(argv[1],argv[2],MED::EVersion(atoi(argv[3])),atoi(argv[4]));
329     return 0;
330   }catch(std::exception& exc){
331     MSG(MYDEBUG,"Follow exception was accured :\n"<<exc.what());
332   }catch(...){
333     MSG(MYDEBUG,"Unknown exception was accured");
334   } 
335   return 1;
336 }