Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDMEM / tests / readCoordinate.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   : readCoordinate.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
31 using namespace std;
32 using namespace MEDMEM;
33
34 #define MED_TAILLE_PNOM  16
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   MED_EN::medModeSwitch Mode = MED_EN::MED_FULL_INTERLACE;
56   if (argc==4)
57   {
58         string comp=argv[3];
59         if ( comp == "MED_NO_INTERLACE" ) Mode = MED_EN::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 << "(* NOEUDS DU MAILLAGE : *)"<<endl;
96   cout << "(************************)"<<endl;
97
98   string typeRepere  = myMesh->getCoordinatesSystem();
99   if ( typeRepere.size() == 0 ) typeRepere ="0";
100   cout << "- Type de repere des coordonnees : " << typeRepere << endl;
101
102   string chainevide(MED_TAILLE_PNOM+2,' ');
103   cout << "- Nom des coordonnees : " << endl ;
104   const string * CoordinatesNames = myMesh->getCoordinatesNames() ;
105   for (int i=0; i < SpaceDimension ; i++) 
106   {
107         string bonnelongueur=chainevide;
108         bonnelongueur.replace(1,CoordinatesNames[i].size(),CoordinatesNames[i]);
109         cout << bonnelongueur;
110   }
111   cout <<endl;
112
113   cout << "- Unites des coordonnees : " << endl ;
114   const string * CoordinatesUnits = myMesh->getCoordinatesUnits() ;
115   for ( int i=0; i < SpaceDimension ; i++) 
116   {
117         string bonnelongueur=chainevide;
118         bonnelongueur.replace(1,CoordinatesUnits[i].size(),CoordinatesUnits[i]);
119         cout << bonnelongueur;
120   }
121   cout <<endl;
122
123   const double * Coordinates = myMesh->getCoordinates(Mode) ;
124   cout << "- Coordonnees des noeuds : " << endl;
125   for (int i=0; i < SpaceDimension*NumberOfNodes; i++)
126   {
127         fprintf(stdout," %f ",Coordinates[i]);
128   }
129   cout <<endl;
130
131   delete myMesh;
132
133 }