Salome HOME
PR: merge from tag mergeto_trunk_17Jan05
[modules/kernel.git] / src / MEDWrapper / MED_Test.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
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 //  File:    VISUConvertor.cxx
24 //  Author:  Alexey PETROV
25 //  Module : VISU
26
27 #include "MED_Structures.hxx"
28 #include "MED_Wrapper.hxx"
29 #include "MED_Utilities.hxx"
30
31 using namespace std;
32
33 #ifdef DEBUG
34 static int MYDEBUG = 1;
35 #else
36 static int MYDEBUG = 0;
37 #endif
38
39
40 void ReadMed(const char* theFileName){
41   using namespace MED;
42   TWrapper aMed(theFileName);
43   string aFileName = theFileName;
44   aFileName += "-";
45   TWrapper aMedW(aFileName);
46
47   int aNbMeshes = aMed.GetNbMeshes();
48   MESSAGE("GetNbMeshes() = "<<aNbMeshes);
49
50   string aName;
51   for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
52     PMeshInfo aMeshInfo(new TMeshInfo());
53     PMeshInfo aNewMeshInfo(new TMeshInfo());
54     aMed.GetMeshInfo(iMesh+1,*aMeshInfo);
55     int aDim = aMeshInfo->myDim;
56     aName = aMeshInfo->GetName();
57     MESSAGE("GetMeshInfo - aName = '"<<aName<<"'; aDim = "<<aDim);
58     *aNewMeshInfo = *aMeshInfo;
59     aName[0] += 1;
60     aNewMeshInfo->SetName(aName);
61     aMedW.SetMeshInfo(*aNewMeshInfo);
62
63     TEntityInfo aEntityInfo = aMed.GetEntityInfo(*aMeshInfo);
64
65     med_int aNbFields = aMed.GetNbFields(); 
66     MESSAGE("GetNbFields() = "<<aNbFields);
67     for(int iField = 0; iField < aNbFields; iField++){
68       med_int aNbComp = aMed.GetNbComp(iField+1);
69       PFieldInfo aFieldInfo(new TFieldInfo(aMeshInfo,aNbComp));
70       aMed.GetFieldInfo(iField+1,*aFieldInfo);
71       MESSAGE("\taName = '"<<aFieldInfo->GetName()<<"'; aNbComp = "<<aNbComp<<"; ");
72       aMedW.SetFieldInfo(*aFieldInfo);
73       med_entite_maillage anEntity;
74       TGeom aTGeom;
75       med_int aNbTimeStamps = aMed.GetNbTimeStamps(*aFieldInfo,aEntityInfo,
76                                                    anEntity,aTGeom);
77       MESSAGE("GetNbTimeStamps = "<<aNbTimeStamps);
78       PTimeStampInfo aTimeStampInfo(new TTimeStampInfo(aFieldInfo,anEntity,aTGeom));
79       for(int iTimeStamp = 0; iTimeStamp < aNbTimeStamps; iTimeStamp++){
80         aMed.GetTimeStampInfo(iTimeStamp+1, *aTimeStampInfo);
81
82         TTimeStampVal aTimeStampVal(aTimeStampInfo);
83         aMed.GetTimeStampVal(aTimeStampVal);
84         aMedW.SetTimeStamp(aTimeStampVal);
85
86         TMeshValue& aMeshValue = aTimeStampVal.myMeshValue;
87         TMeshValue::iterator aMeshValueIter = aMeshValue.begin();
88         for(; aMeshValueIter != aMeshValue.end(); aMeshValueIter++){
89           med_geometrie_element aGeom = aMeshValueIter->first;
90           TValue aValue = aMeshValueIter->second;
91           MESSAGE("\t\taGeom = "<<aGeom<<"; aValue = "<<aValue.size()<<": ");
92           for(int i = 0, iEnd = aValue.size()/aNbComp; i < iEnd; i++){
93             for(int j = 0, ij = i*aNbComp; j < aNbComp; j++, ij++){
94               //MESSAGE(aValue[ij]<<",");
95             }
96             //MESSAGE(" ");
97           }
98           MESSAGE("\n");
99         }
100       }
101     }
102
103     int aNbFam = aMed.GetNbFamilies(*aMeshInfo);
104     MESSAGE("GetNbFamilies() = "<<aNbFam);
105     for(int iFam = 0; iFam < aNbFam; iFam++){
106       int aNbAttr = aMed.GetNbFamAttr(iFam+1,*aMeshInfo);
107       int aNbGroup = aMed.GetNbFamGroup(iFam+1,*aMeshInfo);
108       PFamilyInfo aFamilyInfo(new TFamilyInfo(aMeshInfo,aNbGroup,aNbAttr));
109       aMed.GetFamilyInfo(iFam+1,*aFamilyInfo);
110       aName = aFamilyInfo->GetName();
111       MESSAGE("\taName = '"<<aName<<"'; aNbAttr = "<<aNbAttr<<"; aNbGroup = "<<aNbGroup);
112       aName[0] += 1;
113       aFamilyInfo->SetName(aName);
114       aFamilyInfo->myMeshInfo = aNewMeshInfo;
115       aName = aFamilyInfo->GetName();
116       for(int iGroup = 0; iGroup < aNbGroup; iGroup++){
117         aName = aFamilyInfo->GetGroupName(iGroup);
118         MESSAGE("\t\taGroupName = '"<<aName<<"'");
119         aName[0] += 1;
120         aFamilyInfo->SetGroupName(iGroup,aName);
121       }
122
123       aMedW.SetFamilyInfo(*aFamilyInfo);
124     }
125
126     MESSAGE("GetEntityInfo - aNbEntities = "<<aEntityInfo.size());
127     TEntityInfo::iterator anEntityInfoIter = aEntityInfo.begin();
128     for(; anEntityInfoIter != aEntityInfo.end(); anEntityInfoIter++){
129       const med_entite_maillage& anEntity = anEntityInfoIter->first;
130       MESSAGE("\tanEntity = "<<anEntity);
131       if(anEntity == MED_NOEUD){
132         int aNbNodes = aMed.GetNbNodes(*aMeshInfo);
133         PNodeInfo aNodeInfo(new TNodeInfo(aMeshInfo,aNbNodes));
134         aMed.GetNodeInfo(*aNodeInfo);
135         MESSAGE("\tGetNodeInfo - aNbNodes = "<<aNbNodes<<": ");
136         TNodeCoord& aCoord = aNodeInfo->myCoord;
137         for(int iNode = 0; iNode < aNbNodes; iNode++){
138           for(int iDim = 0, anId = iNode*aDim; iDim < aDim; iDim++, anId++){
139             //MESSAGE(aCoord[anId]<<",");
140             aCoord[anId] += 1.0;
141           }
142           //MESSAGE(" ");
143         }
144         MESSAGE(endl);
145         aNodeInfo->myMeshInfo = aNewMeshInfo;
146         aMedW.SetNodeInfo(*aNodeInfo);
147         continue;
148       }
149       TGeom& aTGeom = anEntityInfoIter->second;
150       TGeom::iterator anTGeomIter = aTGeom.begin();
151       for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
152         const med_geometrie_element& aGeom = anTGeomIter->first;
153         med_int& aNbElem = anTGeomIter->second;
154         MESSAGE("\t\taGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<": ");
155         PCellInfo aCellInfo(new TCellInfo(aMeshInfo,aNbElem,anEntity,aGeom));
156         aMed.GetCellInfo(*aCellInfo);
157         for(int iElem = 0; iElem < aCellInfo->myNbElem; iElem++){
158           int i = iElem*aCellInfo->myConnDim;
159           for(int iConn = 0; iConn < aCellInfo->myConnDim; iConn++, i++){
160             //MESSAGE(aCellInfo->myConn[i]<<",");
161           }
162           //MESSAGE(" ");
163         }
164         MESSAGE(endl);
165         aCellInfo->myMeshInfo = aNewMeshInfo;
166         aMedW.SetCellInfo(*aCellInfo);
167       }
168     }
169     
170   }
171   MESSAGE("OK");
172 }
173
174
175 int main(int argc, char** argv){ 
176   try{
177     if(argc > 1)
178       ReadMed(argv[1]);
179     return 0;
180   }catch(std::exception& exc){
181     MESSAGE("Follow exception was accured :\n"<<exc.what());
182   }catch(...){
183     MESSAGE("Unknown exception was accured in VISU_Convertor_impl");
184   } 
185   return 1;
186 }