Salome HOME
4ba1067f1e013326d052e84660a8a3d8a710078e
[modules/med.git] / src / MEDMEMBinTest / tests / readCoordinate.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  File   : readCoordinate.cxx
21 //  Module : MED
22 //
23 #include<string>
24 #include "MEDMEM_Exception.hxx"
25 #include "MEDMEM_define.hxx"
26 #include "MEDMEM_Mesh.hxx"
27 #include "MEDMEM_MedMeshDriver.hxx"
28
29 using namespace std;
30 using namespace MEDMEM;
31
32 #define MED_TAILLE_PNOM  16
33
34 static void usage(char * name)
35 {
36   cout << "    " << name <<" <file name>"<< " <mesh name> " << " <interlace mode>" << endl;
37   cout << "    " << "displays all Nodes Coordinates in mdump mode" << endl;
38   cout << endl;
39   cout << "    " << "mesh name is mandatory. Try mdump if necessary" << endl;
40   cout << "    " << "values for interlace mode are  : " << endl;
41   cout << "    " << "MED_FULL_INTERLACE (default value) or MED_NO_INTERLACE" << endl;
42   exit(-1);
43 }
44
45 int main (int argc, char ** argv) {
46   
47   if (argc < 3) usage(argv[0]);
48   if (argc > 4) usage(argv[0]);
49
50   string fileName = argv[1];
51   string meshName = argv[2];
52
53   MED_EN::medModeSwitch Mode = MED_EN::MED_FULL_INTERLACE;
54   if (argc==4)
55   {
56         string comp=argv[3];
57         if ( comp == "MED_NO_INTERLACE" ) Mode = MED_EN::MED_NO_INTERLACE;
58         else if ( comp != "MED_FULL_INTERLACE") usage(argv[0]);
59   }
60
61
62   MESH * myMesh= new MESH;
63   myMesh->setName(meshName);
64   MED_MESH_RDONLY_DRIVER myMeshDriver(fileName,myMesh);
65   try
66   {
67        myMeshDriver.setMeshName(meshName);
68        myMeshDriver.open();
69   }
70   catch (const exception & ex)
71   {
72          MESSAGE_MED("Catch Exception : ");
73          SCRUTE_MED(ex.what());
74   };
75   MESSAGE_MED("Open done");
76
77   try
78   {
79        myMeshDriver.read();
80   }
81   catch (const exception & ex)
82   {
83          MESSAGE_MED("Catch Exception : ");
84          SCRUTE_MED(ex.what());
85   };
86   MESSAGE_MED("Read done");
87   
88   int SpaceDimension = myMesh->getSpaceDimension() ;
89   int NumberOfNodes  = myMesh->getNumberOfNodes() ;
90
91   cout << "(************************)"<<endl;
92   cout << "(* NOEUDS DU MAILLAGE : *)"<<endl;
93   cout << "(************************)"<<endl;
94
95   string typeRepere  = myMesh->getCoordinatesSystem();
96   if ( typeRepere.size() == 0 ) typeRepere ="0";
97   cout << "- Type de repere des coordonnees : " << typeRepere << endl;
98
99   string chainevide(MED_TAILLE_PNOM+2,' ');
100   cout << "- Nom des coordonnees : " << endl ;
101   const string * CoordinatesNames = myMesh->getCoordinatesNames() ;
102   for (int i=0; i < SpaceDimension ; i++) 
103   {
104         string bonnelongueur=chainevide;
105         bonnelongueur.replace(1,CoordinatesNames[i].size(),CoordinatesNames[i]);
106         cout << bonnelongueur;
107   }
108   cout <<endl;
109
110   cout << "- Unites des coordonnees : " << endl ;
111   const string * CoordinatesUnits = myMesh->getCoordinatesUnits() ;
112   for ( int i=0; i < SpaceDimension ; i++) 
113   {
114         string bonnelongueur=chainevide;
115         bonnelongueur.replace(1,CoordinatesUnits[i].size(),CoordinatesUnits[i]);
116         cout << bonnelongueur;
117   }
118   cout <<endl;
119
120   const double * Coordinates = myMesh->getCoordinates(Mode) ;
121   cout << "- Coordonnees des noeuds : " << endl;
122   for (int i=0; i < SpaceDimension*NumberOfNodes; i++)
123   {
124         fprintf(stdout," %f ",Coordinates[i]);
125   }
126   cout <<endl;
127
128   myMesh->removeReference();
129
130 }