]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/tests/readCoordinate.cxx
Salome HOME
update from the MedMemory V1.0.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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19 //
20 //
21 //
22 //  File   : readCoordinate.cxx
23 //  Module : MED
24
25 using namespace std;
26 #include<string>
27 #include "MEDMEM_Exception.hxx"
28 #include "MEDMEM_define.hxx"
29 #include "MEDMEM_Mesh.hxx"
30
31 void usage(char * name)
32 {
33   cout << "    " << name <<" <file name>"<< " <mesh name> " << " <interlace mode>" << endl;
34   cout << "    " << "displays all Nodes Coordinates in mdump mode" << endl;
35   cout << endl;
36   cout << "    " << "mesh name is mandatory. Try mdump if necessary" << endl;
37   cout << "    " << "values for interlace mode are  : " << endl;
38   cout << "    " << "MED_FULL_INTERLACE (default value) or MED_NO_INTERLACE" << endl;
39   exit(-1);
40 }
41
42 int main (int argc, char ** argv) {
43   
44   if (argc < 3) usage(argv[0]);
45   if (argc > 4) usage(argv[0]);
46
47   string fileName = argv[1];
48   string meshName = argv[2];
49
50   medModeSwitch Mode = MED_FULL_INTERLACE;
51   if (argc==4)
52   {
53         string comp=argv[3];
54         if ( comp == "MED_NO_INTERLACE" ) Mode = MED_NO_INTERLACE;
55         else if ( comp != "MED_FULL_INTERLACE") usage(argv[0]);
56   }
57
58
59   MESH * myMesh= new MESH() ;
60   myMesh->setName(meshName);
61   MED_MESH_RDONLY_DRIVER myMeshDriver(fileName,myMesh);
62   try
63   {
64        myMeshDriver.setMeshName(meshName);
65        myMeshDriver.open();
66   }
67   catch (const exception & ex)
68   {
69          MESSAGE("Catch Exception : ");
70          SCRUTE(ex.what());
71   };
72   MESSAGE("Open done");
73
74   try
75   {
76        myMeshDriver.read();
77   }
78   catch (const exception & ex)
79   {
80          MESSAGE("Catch Exception : ");
81          SCRUTE(ex.what());
82   };
83   MESSAGE("Read done");
84   
85   int SpaceDimension = myMesh->getSpaceDimension() ;
86   int MeshDimension  = myMesh->getMeshDimension() ;
87   int NumberOfNodes  = myMesh->getNumberOfNodes() ;
88
89   cout << "(************************)"<<endl;
90   cout << "(* NOEUDS DU MAILLAGE : *)"<<endl;
91   cout << "(************************)"<<endl;
92
93   string typeRepere  = myMesh->getCoordinatesSystem();
94   if ( typeRepere.size() == 0 ) typeRepere ="0";
95   cout << "- Type de repere des coordonnees : " << typeRepere << endl;
96
97   string chainevide(MED_TAILLE_PNOM+2,' ');
98   cout << "- Nom des coordonnees : " << endl ;
99   const string * CoordinatesNames = myMesh->getCoordinatesNames() ;
100   for (int i=0; i < SpaceDimension ; i++) 
101   {
102         string bonnelongueur=chainevide;
103         bonnelongueur.replace(1,CoordinatesNames[i].size(),CoordinatesNames[i]);
104         cout << bonnelongueur;
105   }
106   cout <<endl;
107
108   cout << "- Unites des coordonnees : " << endl ;
109   const string * CoordinatesUnits = myMesh->getCoordinatesUnits() ;
110   for ( int i=0; i < SpaceDimension ; i++) 
111   {
112         string bonnelongueur=chainevide;
113         bonnelongueur.replace(1,CoordinatesUnits[i].size(),CoordinatesUnits[i]);
114         cout << bonnelongueur;
115   }
116   cout <<endl;
117
118   const double * Coordinates = myMesh->getCoordinates(Mode) ;
119   cout << "- Coordonnees des noeuds : " << endl;
120   for (int i=0; i < SpaceDimension*NumberOfNodes; i++)
121   {
122         fprintf(stdout," %f ",Coordinates[i]);
123   }
124   cout <<endl;
125
126   delete myMesh;
127
128 }