Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDMEM / tests / readEntete.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //
21 //
22 //  File   : readEntete.cxx
23 //  Module : MED
24
25 #include<string>
26 #include "MEDMEM_Exception.hxx"
27 #include "MEDMEM_define.hxx"
28 #include "MEDMEM_Mesh.hxx"
29 #include "MEDMEM_MedMeshDriver.hxx"
30 #include "MEDMEM_DriversDef.hxx"
31
32 using namespace std;
33 using namespace MEDMEM;
34 using namespace MED_EN;
35
36 void usage(char * name)
37 {
38   cout << "    " << name <<" <file name>"<< " <mesh name> " << " <interlace mode>" << endl;
39   cout << "    " << "displays all Nodes Coordinates in mdump mode" << endl;
40   cout << endl;
41   cout << "    " << "mesh name is mandatory. Try mdump if necessary" << endl;
42   cout << "    " << "values for interlace mode are  : " << endl;
43   cout << "    " << "MED_FULL_INTERLACE (default value) or MED_NO_INTERLACE" << endl;
44   exit(-1);
45 }
46
47 int main (int argc, char ** argv) {
48   
49   if (argc < 3) usage(argv[0]);
50   if (argc > 4) usage(argv[0]);
51
52   string fileName = argv[1];
53   string meshName = argv[2];
54
55   medModeSwitch Mode = MED_FULL_INTERLACE;
56   if (argc==4)
57   {
58         string comp=argv[3];
59         if ( comp == "MED_NO_INTERLACE" ) Mode = MED_NO_INTERLACE;
60         else if ( comp != "MED_FULL_INTERLACE") usage(argv[0]);
61   }
62
63
64   MESH * myMesh= new MESH() ;
65   myMesh->setName(meshName);
66   MED_MESH_RDONLY_DRIVER myMeshDriver(fileName,myMesh);
67   try
68   {
69        myMeshDriver.setMeshName(meshName);
70        myMeshDriver.open();
71   }
72   catch (const exception & ex)
73   {
74          MESSAGE("Catch Exception : ");
75          SCRUTE(ex.what());
76   };
77   MESSAGE("Open done");
78
79   try
80   {
81        myMeshDriver.read();
82   }
83   catch (const exception & ex)
84   {
85          MESSAGE("Catch Exception : ");
86          SCRUTE(ex.what());
87   };
88   MESSAGE("Read done");
89   
90   int SpaceDimension = myMesh->getSpaceDimension();
91   int MeshDimension  = myMesh->getMeshDimension();
92   int NumberOfNodes  = myMesh->getNumberOfNodes();
93
94   cout << "(****************************)" << endl;
95   cout << "(* INFORMATIONS GENERALES : *)" << endl;
96   cout << "(****************************)" << endl;
97
98   //  string chainevide(MED_TAILLE_PNOM+2,' ');
99   cout << "- Nom du maillage : <<"    << meshName       << ">>" << endl;
100   cout << "- Dimension d'espace : "<< SpaceDimension <<  endl;
101   cout << "- Dimension du maillage : "<< MeshDimension <<  endl;
102   cout << "- Pas de nom universel "   << endl ;
103   cout << "- Nombre de noeuds : "     << NumberOfNodes  << " " << endl;
104
105   int NumberOfTypes           = myMesh->getNumberOfTypes(MED_CELL);
106   const medGeometryElement  * Types;
107
108   cout << "- Nombre de Type de mailles : " << NumberOfTypes << endl;
109
110   if (NumberOfTypes > 0)
111     {
112       Types = myMesh->getTypes(MED_CELL);
113
114       cout << "  Types : ";
115       for (int itype=0; itype<NumberOfTypes; itype++) cout << Types[itype] << " ";
116       cout << endl;
117
118       const list<medGeometryElement> currentEntity = meshEntities[MED_CELL];
119       list<medGeometryElement>::const_iterator currentGeometry;
120
121       for (currentGeometry  = currentEntity.begin();
122            currentGeometry != currentEntity.end(); 
123            currentGeometry++) 
124         {
125           cout << "- Nombre de mailles de type "; 
126           cout << geoNames[(*currentGeometry)] << " : ";
127           cout << myMesh->getNumberOfElements(MED_CELL,(MED_EN::medGeometryElement)(*currentGeometry));
128           cout << " " << endl;
129         }
130     }
131
132   NumberOfTypes = myMesh->getNumberOfTypes(MED_FACE);
133   
134   cout << "- Nombre de Type de faces : " << NumberOfTypes << endl;
135
136   if (NumberOfTypes > 0)
137     {
138       Types = myMesh->getTypes(MED_FACE);
139
140       cout << "  Types : ";
141       for (int itype=0; itype<NumberOfTypes; itype++) cout << Types[itype] << " ";
142       cout << endl;
143
144       const list<medGeometryElement> currentEntity2 = meshEntities[MED_FACE];
145       list<medGeometryElement>::const_iterator currentGeometry;
146
147       for (currentGeometry  = currentEntity2.begin();
148            currentGeometry != currentEntity2.end(); 
149            currentGeometry++) 
150         {
151           cout << "- Nombre de faces de type "; 
152           cout << geoNames[(*currentGeometry)] << " : ";
153           cout << myMesh->getNumberOfElements(MED_FACE,(*currentGeometry));
154           cout << " " << endl;
155         }
156     }
157
158   NumberOfTypes = myMesh->getNumberOfTypes(MED_EDGE);
159   
160   cout << "- Nombre de Type de aretes : " << NumberOfTypes << endl;
161
162   if (NumberOfTypes > 0)
163     {
164       Types = myMesh->getTypes(MED_EDGE);
165
166       cout << "  Types : ";
167       for (int itype=0; itype<NumberOfTypes; itype++) cout << Types[itype] << " ";
168       cout << endl;
169
170       const list<medGeometryElement> currentEntity3 = meshEntities[MED_EDGE];
171       list<medGeometryElement>::const_iterator currentGeometry;
172
173       for (currentGeometry  = currentEntity3.begin();
174            currentGeometry != currentEntity3.end(); 
175            currentGeometry++) 
176         {
177           cout << "- Nombre d'aretes de type "; 
178           cout << geoNames[(*currentGeometry)] << " : ";
179           cout << myMesh->getNumberOfElements(MED_EDGE,(*currentGeometry));
180           cout << " " << endl;
181         }
182     }
183
184   delete myMesh;
185 }