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