Salome HOME
96103825dad052a9f77246019535471bb1daa92f
[modules/med.git] / src / MEDMEM / test_copie_group.cxx
1 #include<string>
2
3 #include <math.h>
4 #include <stdlib.h>
5
6 #include "MEDMEM_Exception.hxx"
7 #include "MEDMEM_Mesh.hxx"
8 #include "MEDMEM_Family.hxx"
9 #include "MEDMEM_Group.hxx"
10
11 #include "MEDMEM_MedMeshDriver.hxx"
12 #include "MEDMEM_MedFieldDriver.hxx"
13 #include "MEDMEM_Support.hxx"
14 #include "MEDMEM_Field.hxx"
15 #include "MEDMEM_define.hxx"
16
17 using namespace std;
18 using namespace MEDMEM;
19 using namespace MED_EN;
20
21 void affiche_support(const SUPPORT * mySupport) 
22 {
23   cout << "  - Name : "<<mySupport->getName().c_str()<<endl ;
24   cout << "  - Description : "<<mySupport->getDescription().c_str()<<endl ;
25   cout << "  - Entity : "<<mySupport->getEntity()<<endl ;
26   cout << "  - Entities list : "<<endl ;
27   if (!(mySupport->isOnAllElements())) {
28     int NumberOfTypes = mySupport->getNumberOfTypes() ;
29     cout<<"  - NumberOfTypes : "<<NumberOfTypes<<endl;
30     const medGeometryElement * Types = mySupport->getTypes() ;
31     for (int j=0;j<NumberOfTypes;j++) {
32       cout<<"    * Type "<<Types[j]<<" : ";
33       int NumberOfElements = mySupport->getNumberOfElements(Types[j]) ;
34       const int * Number = mySupport->getNumber(Types[j]) ;
35       for (int k=0; k<NumberOfElements;k++)
36         cout << Number[k] << " ";
37       cout << endl ;
38     }
39   } else
40     cout << "    Is on all entities !"<< endl;
41 }
42
43
44 void affiche_famille(const FAMILY * myFamily)
45 {
46     affiche_support(myFamily);
47     cout << "  - Identifier : "<<myFamily->getIdentifier()<<endl ;
48     int NumberOfAttributes = myFamily->getNumberOfAttributes() ;
49     cout << "  - Attributes ("<<NumberOfAttributes<<") :"<<endl;
50     for (int j=1;j<NumberOfAttributes+1;j++)
51       cout << "    * "<<myFamily->getAttributeIdentifier(j)<<" : "<<myFamily->getAttributeValue(j)<<", "<<myFamily->getAttributeDescription(j).c_str()<<endl ;
52     int NumberOfGroups = myFamily->getNumberOfGroups() ;
53     cout << "  - Groups ("<<NumberOfGroups<<") :"<<endl;
54     for (int j=1;j<NumberOfGroups+1;j++)
55       cout << "    * "<<myFamily->getGroupName(j).c_str()<<endl ;
56 }
57
58 void affiche_groupe(const GROUP * myGroup) 
59 {
60     affiche_support(myGroup);
61     int NumberOfFamillies = myGroup->getNumberOfFamilies() ;
62     cout << "  - Families ("<<NumberOfFamillies<<") :"<<endl;
63     for (int j=1;j<NumberOfFamillies+1;j++)
64       cout << "    * "<<myGroup->getFamily(j)->getName().c_str()<<endl ;
65 }
66
67 int main (int argc, char ** argv) {
68
69   int read;
70
71   if (argc <3) { // after 3, ignored !
72     cerr << "Usage : " << argv[0] 
73          << " filename meshname" << endl << endl;
74     exit(-1);
75   }
76
77   string filename = argv[1] ;
78   string meshname = argv[2] ;
79
80   MESH * myMesh= new MESH() ;
81   myMesh->setName(meshname);
82   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
83   myMeshDriver.setMeshName(meshname);
84   myMeshDriver.open() ;
85   myMeshDriver.read() ;
86   myMeshDriver.close() ;
87
88   const GROUP * myGroup = myMesh->getGroup(MED_NODE,1);
89   cout << "Show Group :"<<endl ;
90   affiche_groupe(myGroup);
91   GROUP * myGroup2 = new GROUP(* myGroup);
92   //delete myGroup; // no because in mesh !!
93   affiche_groupe(myGroup2);
94   GROUP * myGroup3 = new GROUP(* myGroup2);
95   delete myGroup2;
96   affiche_groupe(myGroup3);
97   delete myGroup3;
98
99   delete myMesh ;
100
101   return 0;
102 }