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