]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/test_copie_group.cxx
Salome HOME
sources v1.2
[modules/med.git] / src / MEDMEM / test_copie_group.cxx
1 //  MED MEDMEM : MED files in memory
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   : test_copie_group.cxx
25 //  Module : MED
26
27 using namespace std;
28 #include<string>
29
30 #include <math.h>
31 #include <stdlib.h>
32
33 #include "MEDMEM_Exception.hxx"
34 #include "MEDMEM_Mesh.hxx"
35 #include "MEDMEM_Family.hxx"
36 #include "MEDMEM_Group.hxx"
37
38 #include "MEDMEM_MedMeshDriver.hxx"
39 #include "MEDMEM_MedFieldDriver.hxx"
40 #include "MEDMEM_Support.hxx"
41 #include "MEDMEM_Field.hxx"
42 #include "MEDMEM_define.hxx"
43
44
45 void affiche_support(const SUPPORT * mySupport) 
46 {
47   cout << "  - Name : "<<mySupport->getName().c_str()<<endl ;
48   cout << "  - Description : "<<mySupport->getDescription().c_str()<<endl ;
49   cout << "  - Entity : "<<mySupport->getEntity()<<endl ;
50   cout << "  - Entities list : "<<endl ;
51   if (!(mySupport->isOnAllElements())) {
52     int NumberOfTypes = mySupport->getNumberOfTypes() ;
53     cout<<"  - NumberOfTypes : "<<NumberOfTypes<<endl;
54     const medGeometryElement * Types = mySupport->getTypes() ;
55     for (int j=0;j<NumberOfTypes;j++) {
56       cout<<"    * Type "<<Types[j]<<" : ";
57       int NumberOfElements = mySupport->getNumberOfElements(Types[j]) ;
58       const int * Number = mySupport->getNumber(Types[j]) ;
59       for (int k=0; k<NumberOfElements;k++)
60         cout << Number[k] << " ";
61       cout << endl ;
62     }
63   } else
64     cout << "    Is on all entities !"<< endl;
65 }
66
67
68 void affiche_famille(const FAMILY * myFamily)
69 {
70     affiche_support(myFamily);
71     cout << "  - Identifier : "<<myFamily->getIdentifier()<<endl ;
72     int NumberOfAttributes = myFamily->getNumberOfAttributes() ;
73     cout << "  - Attributes ("<<NumberOfAttributes<<") :"<<endl;
74     for (int j=1;j<NumberOfAttributes+1;j++)
75       cout << "    * "<<myFamily->getAttributeIdentifier(j)<<" : "<<myFamily->getAttributeValue(j)<<", "<<myFamily->getAttributeDescription(j).c_str()<<endl ;
76     int NumberOfGroups = myFamily->getNumberOfGroups() ;
77     cout << "  - Groups ("<<NumberOfGroups<<") :"<<endl;
78     for (int j=1;j<NumberOfGroups+1;j++)
79       cout << "    * "<<myFamily->getGroupName(j).c_str()<<endl ;
80 }
81
82 void affiche_groupe(const GROUP * myGroup) 
83 {
84     affiche_support(myGroup);
85     int NumberOfFamillies = myGroup->getNumberOfFamilies() ;
86     cout << "  - Families ("<<NumberOfFamillies<<") :"<<endl;
87     for (int j=1;j<NumberOfFamillies+1;j++)
88       cout << "    * "<<myGroup->getFamily(j)->getName().c_str()<<endl ;
89 }
90
91 int main (int argc, char ** argv) {
92
93   int read;
94
95   if (argc <3) { // after 3, ignored !
96     cerr << "Usage : " << argv[0] 
97          << " filename meshname" << endl << endl;
98     exit(-1);
99   }
100
101   string filename = argv[1] ;
102   string meshname = argv[2] ;
103
104   MESH * myMesh= new MESH() ;
105   myMesh->setName(meshname);
106   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
107   myMeshDriver.setMeshName(meshname);
108   myMeshDriver.open() ;
109   myMeshDriver.read() ;
110   myMeshDriver.close() ;
111
112   const GROUP * myGroup = myMesh->getGroup(MED_NODE,1);
113   cout << "Show Group :"<<endl ;
114   affiche_groupe(myGroup);
115   GROUP * myGroup2 = new GROUP(* myGroup);
116   //delete myGroup; // no because in mesh !!
117   affiche_groupe(myGroup2);
118   GROUP * myGroup3 = new GROUP(* myGroup2);
119   delete myGroup2;
120   affiche_groupe(myGroup3);
121   delete myGroup3;
122
123   delete myMesh ;
124
125   return 0;
126 }