1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 // File : testUCoordinate.cxx
27 #include "MEDMEM_Utilities.hxx"
29 #include "MEDMEM_define.hxx"
30 #include "MEDMEM_Array.hxx"
31 #include "MEDMEM_Coordinate.hxx"
35 using namespace MEDMEM;
37 void usage(char * name)
39 cout << " " << name << endl;
42 int main (int argc, char ** argv)
46 if (argc < 1) usage(argv[0]);
48 const double pouieme = 0.009;
50 cout << "COORDINATE Test" << endl;
51 cout << "---------------" << endl;
56 string * noms = new string[3];
66 int * numbers=new int[5];
67 for (int i=0; i< 5; i++) numbers[i] =10+i;
69 MED_EN::medModeSwitch ModeFull=MED_EN::MED_FULL_INTERLACE;
70 MED_EN::medModeSwitch ModeNo=MED_EN::MED_NO_INTERLACE;
71 double coor[15] = {0,0,0,0,0,1,0,1,0,1,0,0,0.5,0.5,0.5} ;
72 ASSERT(SpaceDim*NbOfNodes == 15);
75 cout << " - mode : MED_FULL_INTERLACE" << endl;
76 cout << " - dimension de l espace : " << SpaceDim << endl;
77 cout << " - nombre de noeuds : " << NbOfNodes << endl;
79 double * coor1 = new double[SpaceDim*NbOfNodes];
80 for( int k=0 ; k<SpaceDim*NbOfNodes ; k++ )
83 MEDARRAY<double>* CoordinateArray = new MEDARRAY<double>(coor1,SpaceDim,NbOfNodes,ModeFull);
87 mycoo.setCoordinates(CoordinateArray);
89 catch ( const std::exception &e )
91 cout << "-------------------------------" << endl;
92 cout << "pb avec setCoordinates" << endl;
93 cout << "-------------------------------" << endl;
94 MESSAGE( "catched exception : " << e.what() ) ;
99 cout << "-------------------------------" << endl;
100 cout << "pb avec setCoordinates" << endl;
101 cout << "-------------------------------" << endl;
102 return EXIT_FAILURE ;
105 //--------------------------------------------------------------------//
106 // Tests des methodes //
108 // - setCoordinatesNames //
109 // - setCoordinatesUnits //
110 // - setCoordinatesSystem //
111 // - setNodesNumbers //
113 //--------------------------------------------------------------------//
116 mycoo.setCoordinatesNames(noms);
118 catch ( const std::exception &e )
120 cout << "-------------------------------" << endl;
121 cout << "pb avec setCoordinatesNames" << endl;
122 cout << "-------------------------------" << endl;
123 MESSAGE( "catched exception : " << e.what() ) ;
124 return EXIT_FAILURE ;
128 cout << "-------------------------------" << endl;
129 cout << "pb avec setCoordinatesNames" << endl;
130 cout << "-------------------------------" << endl;
131 return EXIT_FAILURE ;
136 mycoo.setCoordinatesUnits(units);
138 catch ( const std::exception &e )
140 cout << "-------------------------------" << endl;
141 cout << "pb avec setCoordinatesUnits" << endl;
142 cout << "-------------------------------" << endl;
143 MESSAGE( "catched exception : " << e.what() ) ;
144 return EXIT_FAILURE ;
148 cout << "-------------------------------" << endl;
149 cout << "pb avec setCoordinatesUnits" << endl;
150 cout << "-------------------------------" << endl;
151 return EXIT_FAILURE ;
156 mycoo.setCoordinatesSystem("cartesien");
158 catch ( const std::exception &e )
160 cout << "-------------------------------" << endl;
161 cout << "pb avec setCoordinatesSystem" << endl;
162 cout << "-------------------------------" << endl;
163 MESSAGE( "catched exception : " << e.what() ) ;
164 return EXIT_FAILURE ;
168 cout << "-------------------------------" << endl;
169 cout << "pb avec setCoordinatesSystem" << endl;
170 cout << "-------------------------------" << endl;
171 return EXIT_FAILURE ;
176 mycoo.setNodesNumbers(numbers);
178 catch ( const std::exception &e )
180 cout << "-------------------------------" << endl;
181 cout << "pb avec setNodesNumbers" << endl;
182 cout << "-------------------------------" << endl;
183 MESSAGE( "catched exception : " << e.what() ) ;
184 return EXIT_FAILURE ;
188 cout << "-------------------------------" << endl;
189 cout << "pb avec setNodesNumbers" << endl;
190 cout << "-------------------------------" << endl;
191 return EXIT_FAILURE ;
194 //--------------------------------------------------------------------//
195 // Tests des methodes //
197 // - getCoordinatesNames //
198 // - getCoordinatesUnits //
199 // - getCoordinatesUnit //
200 // - getCoordinatesSystem //
201 // - getNodesNumbers //
203 //--------------------------------------------------------------------//
205 cout << endl << " Relecture des Coordonnees" << endl << endl;
209 cout << " Le systeme est : " << mycoo.getCoordinatesSystem() << endl;
211 catch ( const std::exception &e )
213 cout << "-------------------------------" << endl;
214 cout << "pb avec getCoordinatesSystem" << endl;
215 cout << "-------------------------------" << endl;
216 MESSAGE( "catched exception : " << e.what() ) ;
217 return EXIT_FAILURE ;
221 cout << "-------------------------------" << endl;
222 cout << "pb avec getCoordinatesSystem" << endl;
223 cout << "-------------------------------" << endl;
224 return EXIT_FAILURE ;
227 const string * units2;
230 units2=mycoo.getCoordinatesUnits();
231 for (int axe = 0; axe < SpaceDim; axe++)
235 string verif = mycoo.getCoordinateUnit(axe+1);
236 if (verif != units2[axe])
237 cout << "Pb avec les noms des axes" << endl;
239 catch ( const std::exception &e )
241 cout << "-------------------------" << endl;
242 cout << "pb avec getCoordinateUnit" << endl;
243 cout << "-------------------------" << endl;
244 MESSAGE( "catched exception : " << e.what() ) ;
245 return EXIT_FAILURE ;
249 cout << "-------------------------" << endl;
250 cout << "pb avec getCoordinateUnit" << endl;
251 cout << "-------------------------" << endl;
252 return EXIT_FAILURE ;
256 catch ( const std::exception &e )
258 cout << "---------------------------" << endl;
259 cout << "pb avec getCoordinatesUnits" << endl;
260 cout << "---------------------------" << endl;
261 MESSAGE( "catched exception : " << e.what() ) ;
262 return EXIT_FAILURE ;
266 cout << "---------------------------" << endl;
267 cout << "pb avec getCoordinatesUnits" << endl;
268 cout << "---------------------------" << endl;
269 return EXIT_FAILURE ;
272 const string * noms2;
275 noms2=mycoo.getCoordinatesNames();
276 for (int axe = 0; axe < SpaceDim; axe++)
280 string verif = mycoo.getCoordinateName(axe+1);
281 if (verif != noms2[axe])
282 cout << "Pb avec les noms des axes" << endl;
284 catch ( const std::exception &e )
286 cout << "-------------------------" << endl;
287 cout << "pb avec getCoordinateName" << endl;
288 cout << "-------------------------" << endl;
289 MESSAGE( "catched exception : " << e.what() ) ;
290 return EXIT_FAILURE ;
294 cout << "-------------------------" << endl;
295 cout << "pb avec getCoordinateName" << endl;
296 cout << "-------------------------" << endl;
297 return EXIT_FAILURE ;
301 catch ( const std::exception &e )
303 cout << "---------------------------" << endl;
304 cout << "pb avec getCoordinatesNames" << endl;
305 cout << "---------------------------" << endl;
306 MESSAGE( "catched exception : " << e.what() ) ;
307 return EXIT_FAILURE ;
311 cout << "---------------------------" << endl;
312 cout << "pb avec getCoordinatesNames" << endl;
313 cout << "---------------------------" << endl;
314 return EXIT_FAILURE ;
320 const double * coor2=mycoo.getCoordinates(ModeFull);
322 for (int axe = 0; axe < SpaceDim; axe++)
325 cout << "Coordonnees sur l'Axe : " << noms2[axe] ;
326 cout << " dont l unite est " << units2[axe] << endl;
330 const double * coor3=mycoo.getCoordinateAxis(axe+1);
331 for (int num=0; num < NbOfNodes; num++)
335 const double d = mycoo.getCoordinate(num + 1,axe+1);
337 ASSERT(fabs(d - coor3[num]) < pouieme);
338 ASSERT(fabs(d - coor2[(num * SpaceDim)+axe]) < pouieme);
339 ASSERT(fabs(d - coor [(num * SpaceDim)+axe]) < pouieme);
341 catch ( const std::exception &e )
343 cout << "----------------------" << endl;
344 cout << "pb avec getCoordinates" << endl;
345 cout << "----------------------" << endl;
346 MESSAGE( "catched exception : " << e.what() ) ;
347 return EXIT_FAILURE ;
351 cout << "----------------------" << endl;
352 cout << "pb avec getCoordinates" << endl;
353 cout << "----------------------" << endl;
354 return EXIT_FAILURE ;
359 catch ( const std::exception &e )
361 cout << "-------------------------" << endl;
362 cout << "pb avec getCoordinateAxis" << endl;
363 cout << "-------------------------" << endl;
364 MESSAGE( "catched exception : " << e.what() ) ;
365 return EXIT_FAILURE ;
369 cout << "-------------------------" << endl;
370 cout << "pb avec getCoordinateAxis" << endl;
371 cout << "-------------------------" << endl;
372 return EXIT_FAILURE ;
376 catch ( const std::exception &e )
378 cout << "----------------------" << endl;
379 cout << "pb avec getCoordinates" << endl;
380 cout << "----------------------" << endl;
381 MESSAGE( "catched exception : " << e.what() ) ;
382 return EXIT_FAILURE ;
386 cout << "----------------------" << endl;
387 cout << "pb avec getCoordinates" << endl;
388 cout << "----------------------" << endl;
389 return EXIT_FAILURE ;
397 delete CoordinateArray ;
399 MESSAGE("FIN normale du traitement");
400 return EXIT_SUCCESS ;