Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / MEDMEMBinTest / test_copie_coordinate.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /* Programme de test du constructeur de copies de la classe COORDINATE de MEDMEM
23    jroy - 17/12/2002 */
24
25 #include <string>
26
27 #include <math.h>
28 #include <stdlib.h>
29
30 #include "MEDMEM_Exception.hxx"
31 #include "MEDMEM_Mesh.hxx"
32 #include "MEDMEM_Family.hxx"
33 #include "MEDMEM_Group.hxx"
34
35 #include "MEDMEM_MedMeshDriver.hxx"
36 #include "MEDMEM_MedFieldDriver.hxx"
37 #include "MEDMEM_Support.hxx"
38 #include "MEDMEM_Field.hxx"
39 #include "MEDMEM_define.hxx"
40
41 using namespace std;
42 using namespace MEDMEM;
43 using namespace MED_EN;
44
45 static void affiche_tableau(const double * myArray, int nb_lignes, int nb_colonnes)
46 {
47   cout << "Nombre de lignes : " << nb_lignes << endl;
48   cout << "Nombre de colonnes : " << nb_colonnes << endl;
49   cout << "Valeurs :" << endl;
50
51   for (int i=0; i<nb_lignes; i++) {
52     for (int j=0; j<nb_colonnes; j++)
53       cout << myArray[j*nb_lignes+i] << " ";
54     cout << endl;}
55 }
56
57 static void affiche_coordinate(COORDINATE & myCoordinate, int _numberofNodes, int _spaceDimension)
58 {
59   cout << "- Système de coordonnées : " << myCoordinate.getCoordinatesSystem() << endl;
60   cout << "- Tableau des coordonnées : " << endl;
61   //  affiche_medarray(* myCoordinate.getCoordinatePtr());
62   affiche_tableau(myCoordinate.getCoordinates(MED_NO_INTERLACE),_numberofNodes,_spaceDimension);
63   //on récupère les dimensions
64   //  int _spaceDimension = (int) myCoordinate.getCoordinatePtr()->getLeadingValue();
65   //int _numberofNodes = (int) myCoordinate.getCoordinatePtr()->getLengthValue();
66   cout << "- Nom des coordonnées : " << endl;
67   for (int i=1; i<=_spaceDimension; i++)
68     cout << i << "   " << myCoordinate.getCoordinateName(i) << endl;
69   //  cout<<myCoordinate.getCoordinatesNames()<<endl;
70   cout << "- Unité des coordonnées : " << endl;
71   for (int i=1; i<=_spaceDimension; i++)
72     cout << i << "   " << myCoordinate.getCoordinateUnit(i) << endl;
73   cout << "- Indices des noeuds : " << endl;
74   //  cout<<myCoordinate.getNodesNumbers()<<endl;
75   for (int i=0; i<_numberofNodes; i++)
76     cout << i << "   " << myCoordinate.getNodesNumbers()[i] << endl;
77 }
78
79
80 int main (int argc, char ** argv) {
81   /*
82   if ((argc !=3) && (argc != 4)) {
83     cerr << "Usage : " << argv[0] 
84          << " filename meshname fieldname" << endl << endl;
85     exit(-1);
86   }
87   */
88   const med_int numberofNodes = 5;
89   const med_int spaceDimension = 3;
90   const medModeSwitch mode = MED_FULL_INTERLACE;
91
92   //construction tableau MEDARRAY des coordonnées
93   MEDARRAY<double> * myMedArray = new MEDARRAY<double>(spaceDimension,numberofNodes,mode);
94   for (med_int i=1; i<=myMedArray->getLengthValue(); i++) {
95     for (med_int j=1; j<=myMedArray->getLeadingValue(); j++)
96       myMedArray->setIJ(i,j,(double) rand());
97   };
98
99   //construction noms des coordonnées
100   string * myCoordinatesNames = new string[spaceDimension];
101   if (spaceDimension >= 1) myCoordinatesNames[0] = "x";
102   if (spaceDimension >= 2) myCoordinatesNames[1] = "y";
103   if (spaceDimension >= 3) myCoordinatesNames[2] = "z";
104
105   //construction unités des coordonnées
106   string * myCoordinatesUnits = new string[spaceDimension];
107   if (spaceDimension >= 1) myCoordinatesUnits[0] = "m";
108   if (spaceDimension >= 2) myCoordinatesUnits[1] = "m";
109   if (spaceDimension >= 3) myCoordinatesUnits[2] = "m";
110
111   //construction des indices des noeuds
112   int * myNodeNumber = new int[numberofNodes];
113   for (int i=0; i<numberofNodes; i++)
114     myNodeNumber[i]=numberofNodes-i-1;
115
116   //construction de l'objet COORDINATE
117   COORDINATE * myCoordinate = new COORDINATE();
118   myCoordinate->setCoordinates(myMedArray);
119   myCoordinate->setCoordinatesNames(myCoordinatesNames);
120   myCoordinate->setCoordinatesUnits(myCoordinatesUnits);
121   myCoordinate->setNodesNumbers(myNodeNumber);
122
123   //  myCoordinate->setCoordinatesNames((string *)NULL);
124   //  myCoordinate->setNodesNumbers((int *) NULL);
125
126   delete myMedArray ;
127   delete[] myCoordinatesNames ;
128   delete[] myCoordinatesUnits ;
129   delete[] myNodeNumber ;
130
131   affiche_coordinate(* myCoordinate,numberofNodes,spaceDimension);
132   COORDINATE * myCoordinate2 = new COORDINATE(* myCoordinate);
133   delete myCoordinate ;
134
135   affiche_coordinate(* myCoordinate2,numberofNodes,spaceDimension);
136   delete myCoordinate2 ;
137
138   return 0;
139 }